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
72
73
74
75
76
77
78
79
80
|
public class MySource extends Activity
{
private ArrayList<String> dt=new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
for(int i=0;i<10;i++)
{
dt.add("A"+i);
}
MyAdapter adapter=new MyAdapter(MySource.this, dt);
ListView lv=(ListView)findViewById(R.id.ListView01);
lv.setAdapter(adapter);
}
}
class MyAdapter extends BaseAdapter
{
private Context context;
private LayoutInflater m_inflater;
private ArrayList<String> dt;
public MyAdapter(Context context, ArrayList<String> dt)
{
m_inflater = LayoutInflater.from(context);
this.context=context;
this.dt=dt;
}
@Override
public int getCount()
{
return dt.size();
}
@Override
public Object getItem(int arg0)
{
return dt.get(arg0);
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
if(convertView==null)
{
convertView=m_inflater.inflate(R.layout.lite_item, null);
}
final TextView tv=(TextView)convertView.findViewById(R.id.TextView01);
ImageButton ib=(ImageButton)convertView.findViewById(R.id.ImageButton01);
tv.setText(dt.get(position));
ib.setBackgroundDrawable(convertView.getResources().getDrawable(android.R.drawable.btn_dialog));
ib.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
tv.setText("Click!!!");
}
});
return convertView;
}
}
|