PersonalSelectAdapter.java
1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.studymachine.www.ui.adapter;
import android.content.Context;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatTextView;
import com.studymachine.www.R;
import com.studymachine.www.app.AppAdapter;
/**
* desc : 个人中心 按钮选择
*/
public final class PersonalSelectAdapter extends AppAdapter<String> {
private int mSelectIndex = 0;
public PersonalSelectAdapter(Context context) {
super(context);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ViewHolder();
}
public int getSelectIndex() {
return mSelectIndex;
}
public void setSelectIndex(int selectIndex) {
if (selectIndex == this.mSelectIndex) return;
int oldSelectIndex = this.mSelectIndex;
this.mSelectIndex = selectIndex;
if (oldSelectIndex != -1) {
notifyItemChanged(oldSelectIndex);
}
notifyItemChanged(selectIndex);
}
private final class ViewHolder extends AppAdapter<?>.ViewHolder {
private AppCompatTextView mTvName;
private ViewHolder() {
super(R.layout.personal_select_item);
initView();
}
@Override
public void onBindView(int position) {
if (getData() != null) {
mTvName.setText(getData().get(position));
if (mSelectIndex != position) {
mTvName.setBackground(null);
mTvName.setTextColor(getColor(R.color.white60));
} else {
mTvName.setBackgroundResource(R.drawable.person_daohang);
mTvName.setTextColor(getColor(R.color.white));
}
}
}
private void initView() {
mTvName = findViewById(R.id.tv_name);
}
}
}