Browse Source

added selected state for stop routes items

tags/v1.0.0
Robin Thoni 7 years ago
parent
commit
ebc8468f4f

+ 1
- 0
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopPickerFragment.java View File

135
         _stopsAdapter = new StopsAdapter();
135
         _stopsAdapter = new StopsAdapter();
136
         _listStops.setAdapter(_stopsAdapter);
136
         _listStops.setAdapter(_stopsAdapter);
137
         _listStops.setLayoutManager(new LinearLayoutManager(getContext()));
137
         _listStops.setLayoutManager(new LinearLayoutManager(getContext()));
138
+        _listStops.setHasFixedSize(true);
138
 
139
 
139
         _searchText.addTextChangedListener(new TextWatcher() {
140
         _searchText.addTextChangedListener(new TextWatcher() {
140
             Handler handler = new Handler(Looper.getMainLooper() /*UI thread*/);
141
             Handler handler = new Handler(Looper.getMainLooper() /*UI thread*/);

+ 6
- 3
app/src/main/java/com/rthoni/stssaguenay/ui/fragments/StopRoutesPickerFragment.java View File

46
     public static class ViewHolder extends RecyclerView.ViewHolder {
46
     public static class ViewHolder extends RecyclerView.ViewHolder {
47
         public ImageView _imageView;
47
         public ImageView _imageView;
48
         public TextView _textView;
48
         public TextView _textView;
49
+        public View _view;
49
         public ViewHolder(View v) {
50
         public ViewHolder(View v) {
50
             super(v);
51
             super(v);
52
+            _view = v;
51
         }
53
         }
52
     }
54
     }
53
 
55
 
74
                     .endConfig()
76
                     .endConfig()
75
                     .buildRound(routeDbo.getId(), Color.parseColor("#" + routeDbo.getBgColor()));
77
                     .buildRound(routeDbo.getId(), Color.parseColor("#" + routeDbo.getBgColor()));
76
             holder._imageView.setImageDrawable(drawable);
78
             holder._imageView.setImageDrawable(drawable);
77
-            holder._textView.setText(routeDbo.getFullName());
78
-            holder._textView.setOnClickListener(new View.OnClickListener() {
79
+            holder._textView.setText(routeDbo.getName());
80
+            holder._view.setOnClickListener(new View.OnClickListener() {
79
                 @Override
81
                 @Override
80
                 public void onClick(View v) {
82
                 public void onClick(View v) {
81
-//                    onStopSelected(routeDbo);
83
+                    v.setSelected(!v.isSelected());
82
                 }
84
                 }
83
             });
85
             });
84
         }
86
         }
105
         _routesAdapter = new RoutesAdapter();
107
         _routesAdapter = new RoutesAdapter();
106
         _listRoutes.setAdapter(_routesAdapter);
108
         _listRoutes.setAdapter(_routesAdapter);
107
         _listRoutes.setLayoutManager(new LinearLayoutManager(getContext()));
109
         _listRoutes.setLayoutManager(new LinearLayoutManager(getContext()));
110
+        _listRoutes.setHasFixedSize(true);
108
 
111
 
109
         loadRoutes();
112
         loadRoutes();
110
 
113
 

+ 4
- 0
app/src/main/res/drawable/recycler_view_selector.xml View File

1
+<?xml version="1.0" encoding="utf-8"?>
2
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
3
+    <item android:drawable="@android:color/holo_blue_dark" android:state_selected="true"/>
4
+</selector>

+ 11
- 3
app/src/main/res/layout/route_recycler_view_item.xml View File

2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3
               android:orientation="horizontal"
3
               android:orientation="horizontal"
4
               android:layout_width="match_parent"
4
               android:layout_width="match_parent"
5
-              android:layout_height="wrap_content">
5
+              android:layout_height="wrap_content"
6
+              android:foreground="?android:attr/selectableItemBackground"
7
+              android:background="@drawable/recycler_view_selector"
8
+              android:minHeight="?android:attr/listPreferredItemHeightSmall"
9
+              android:clickable="true"
10
+              android:focusable="true">
6
 
11
 
7
     <ImageView
12
     <ImageView
8
         android:layout_width="50dp"
13
         android:layout_width="50dp"
15
 
20
 
16
     <TextView
21
     <TextView
17
         android:text="TextView"
22
         android:text="TextView"
18
-        android:layout_width="match_parent"
23
+        android:layout_width="wrap_content"
19
         android:layout_height="match_parent"
24
         android:layout_height="match_parent"
20
         android:id="@+id/textView"
25
         android:id="@+id/textView"
21
-        android:gravity="center_vertical"/>
26
+        android:gravity="center_vertical"
27
+        android:clickable="false"
28
+        android:focusable="false"/>
29
+
22
 </LinearLayout>
30
 </LinearLayout>

Loading…
Cancel
Save