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,6 +135,7 @@ public class StopPickerFragment extends Fragment {
135 135
         _stopsAdapter = new StopsAdapter();
136 136
         _listStops.setAdapter(_stopsAdapter);
137 137
         _listStops.setLayoutManager(new LinearLayoutManager(getContext()));
138
+        _listStops.setHasFixedSize(true);
138 139
 
139 140
         _searchText.addTextChangedListener(new TextWatcher() {
140 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,8 +46,10 @@ public class StopRoutesPickerFragment extends Fragment {
46 46
     public static class ViewHolder extends RecyclerView.ViewHolder {
47 47
         public ImageView _imageView;
48 48
         public TextView _textView;
49
+        public View _view;
49 50
         public ViewHolder(View v) {
50 51
             super(v);
52
+            _view = v;
51 53
         }
52 54
     }
53 55
 
@@ -74,11 +76,11 @@ public class StopRoutesPickerFragment extends Fragment {
74 76
                     .endConfig()
75 77
                     .buildRound(routeDbo.getId(), Color.parseColor("#" + routeDbo.getBgColor()));
76 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 81
                 @Override
80 82
                 public void onClick(View v) {
81
-//                    onStopSelected(routeDbo);
83
+                    v.setSelected(!v.isSelected());
82 84
                 }
83 85
             });
84 86
         }
@@ -105,6 +107,7 @@ public class StopRoutesPickerFragment extends Fragment {
105 107
         _routesAdapter = new RoutesAdapter();
106 108
         _listRoutes.setAdapter(_routesAdapter);
107 109
         _listRoutes.setLayoutManager(new LinearLayoutManager(getContext()));
110
+        _listRoutes.setHasFixedSize(true);
108 111
 
109 112
         loadRoutes();
110 113
 

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

@@ -0,0 +1,4 @@
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,7 +2,12 @@
2 2
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 3
               android:orientation="horizontal"
4 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 12
     <ImageView
8 13
         android:layout_width="50dp"
@@ -15,8 +20,11 @@
15 20
 
16 21
     <TextView
17 22
         android:text="TextView"
18
-        android:layout_width="match_parent"
23
+        android:layout_width="wrap_content"
19 24
         android:layout_height="match_parent"
20 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 30
 </LinearLayout>

Loading…
Cancel
Save