Commit 7bcb60ecb98a6185d86a11e5be0f29771c5b48d3
1 parent
6eabc0ad3d
Exists in
master
首页科目选中/非选中效果
Showing
11 changed files
with
48 additions
and
16 deletions
Show diff stats
app/src/main/java/com/hjx/parent/fragment/ErrorFragment.java
... | ... | @@ -14,6 +14,7 @@ import android.util.Log; |
14 | 14 | import android.view.LayoutInflater; |
15 | 15 | import android.view.View; |
16 | 16 | import android.view.ViewGroup; |
17 | +import android.widget.TextView; | |
17 | 18 | import android.widget.Toast; |
18 | 19 | |
19 | 20 | import androidx.annotation.NonNull; |
... | ... | @@ -122,33 +123,37 @@ public class ErrorFragment extends BaseRxFragment<FragmentErrorBookBinding> { |
122 | 123 | |
123 | 124 | @Override |
124 | 125 | protected void convert(@NonNull BaseViewHolder item, Object o) { |
125 | - item.setText(R.id.tv_subject, getResources().getStringArray(R.array.filter_subject)[item.getAdapterPosition()]); | |
126 | - switch (item.getAdapterPosition()) { | |
127 | - case 0: | |
128 | - item.setImageResource(R.id.iv_subject, R.drawable.png_ic_chinese); | |
126 | + int position = item.getBindingAdapterPosition(); | |
127 | + String name = getResources().getStringArray(R.array.filter_subject)[position]; | |
128 | + item.setText(R.id.tv_subject, name); | |
129 | + switch (name) { | |
130 | + case "语文": | |
131 | + item.setImageResource(R.id.iv_subject, R.drawable.state_ic_chinese); | |
129 | 132 | break; |
130 | - case 1: | |
131 | - item.setImageResource(R.id.iv_subject, R.drawable.png_ic_math); | |
133 | + case "数学": | |
134 | + item.setImageResource(R.id.iv_subject, R.drawable.state_ic_math); | |
132 | 135 | break; |
133 | - case 2: | |
134 | - item.setImageResource(R.id.iv_subject, R.drawable.png_ic_english); | |
136 | + case "英语": | |
137 | + item.setImageResource(R.id.iv_subject, R.drawable.state_ic_english); | |
135 | 138 | break; |
136 | - case 3: | |
137 | - item.setImageResource(R.id.iv_subject, R.drawable.png_ic_physics); | |
139 | + case "物理": | |
140 | + item.setImageResource(R.id.iv_subject, R.drawable.state_ic_physics); | |
138 | 141 | break; |
139 | - case 4: | |
140 | - item.setImageResource(R.id.iv_subject, R.drawable.png_ic_chemistry); | |
142 | + case "化学": | |
143 | + item.setImageResource(R.id.iv_subject, R.drawable.state_ic_chemistry); | |
141 | 144 | break; |
142 | 145 | } |
146 | + item.itemView.setActivated(subject == position); | |
143 | 147 | ViewGroup.LayoutParams layoutParams = item.getView(R.id.rl_subject).getLayoutParams(); |
144 | - layoutParams.width = (CommonUtil.getScreenWidth(getContext()) - CommonUtil.dpToPx(getContext(), 30)) / 4; | |
148 | + layoutParams.width = (CommonUtil.getScreenWidth(mContext) - CommonUtil.dpToPx(mContext, 30)) / 4; | |
145 | 149 | item.getView(R.id.rl_subject).setLayoutParams(layoutParams); |
146 | - item.getConvertView().setOnClickListener(v -> { | |
147 | - if (subject != item.getAdapterPosition()) { | |
148 | - subject = item.getAdapterPosition(); | |
150 | + item.itemView.setOnClickListener(v -> { | |
151 | + if (subject != position) { | |
152 | + subject = position; | |
149 | 153 | String subStr = getResources().getStringArray(R.array.filter_subject)[subject]; |
150 | 154 | getError(subStr); |
151 | 155 | getHomework(subStr); |
156 | + notifyDataSetChanged(); | |
152 | 157 | } |
153 | 158 | }); |
154 | 159 | } | ... | ... |
app/src/main/res/drawable/png_ic_chemistry_off.png
12.3 KB
app/src/main/res/drawable/png_ic_chinese_off.png
11.1 KB
app/src/main/res/drawable/png_ic_english_off.png
13.9 KB
app/src/main/res/drawable/png_ic_math_off.png
10.8 KB
app/src/main/res/drawable/png_ic_physics_off.png
11.8 KB
app/src/main/res/drawable/state_ic_chemistry.xml
... | ... | @@ -0,0 +1,5 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
3 | + <item android:drawable="@drawable/png_ic_chemistry" android:state_activated="true"/> | |
4 | + <item android:drawable="@drawable/png_ic_chemistry_off"/> | |
5 | +</selector> | |
0 | 6 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/state_ic_chinese.xml
... | ... | @@ -0,0 +1,5 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
3 | + <item android:drawable="@drawable/png_ic_chinese" android:state_activated="true"/> | |
4 | + <item android:drawable="@drawable/png_ic_chinese_off" /> | |
5 | +</selector> | |
0 | 6 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/state_ic_english.xml
... | ... | @@ -0,0 +1,5 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
3 | + <item android:drawable="@drawable/png_ic_english" android:state_activated="true"/> | |
4 | + <item android:drawable="@drawable/png_ic_english_off"/> | |
5 | +</selector> | |
0 | 6 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/state_ic_math.xml
... | ... | @@ -0,0 +1,7 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
3 | + | |
4 | + <item android:drawable="@drawable/png_ic_math" android:state_activated="true"/> | |
5 | + <item android:drawable="@drawable/png_ic_math_off"/> | |
6 | + | |
7 | +</selector> | |
0 | 8 | \ No newline at end of file | ... | ... |
app/src/main/res/drawable/state_ic_physics.xml
... | ... | @@ -0,0 +1,5 @@ |
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<selector xmlns:android="http://schemas.android.com/apk/res/android"> | |
3 | + <item android:drawable="@drawable/png_ic_physics" android:state_activated="true"/> | |
4 | + <item android:drawable="@drawable/png_ic_physics_off"/> | |
5 | +</selector> | |
0 | 6 | \ No newline at end of file | ... | ... |