ChooseAdapter.java
1.77 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
package com.lijinji.scan.adapter;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.lijinji.scan.R;
import java.util.ArrayList;
import java.util.List;
public class ChooseAdapter extends BaseAdapter {
private Context mContext;
private List<ChooseBean> mList = new ArrayList<>();
public ChooseAdapter(Context context) {
this.mContext = context;
}
public List<ChooseBean> getList() {
return mList;
}
public void setList(List<ChooseBean> list) {
mList = list;
}
@Override
public int getCount() {
return mList.size();
}
@Override
public Object getItem(int i) {
return mList.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int position, View convertView, ViewGroup viewGroup) {
ViewHolder viewHolder = new ViewHolder();
if (convertView == null) {
convertView = LayoutInflater.from(mContext).inflate(R.layout.choose_list_item, null);
viewHolder.icon = (ImageView) convertView.findViewById(R.id.icon);
viewHolder.name = (TextView) convertView.findViewById(R.id.name);
convertView.setTag(viewHolder);
} else {
viewHolder = (ViewHolder) convertView.getTag();
}
final ChooseBean bean = (ChooseBean) mList.get(position);
viewHolder.icon.setImageDrawable(bean.getDrawable());
viewHolder.name.setText(bean.getName());
return convertView;
}
private class ViewHolder {
TextView name;
ImageView icon;
}
}