public class
Main
extends
Activity {
private
ListView list;
private
ListAdapter listadapter;
private
String[] arr;
/** Called when the activity is first created. */
@Override
public
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.main);
arr=
new
String[]{
"111"
,
"222"
,
"333"
};
list = (ListView) findViewById(R.id.ListView);
listadapter =
new
ListAdapter();
list.setAdapter(listadapter);
list.setOnItemClickListener(
new
OnItemClickListener() {
public
void
onItemClick(AdapterView<?> parent, View view,
int
position,
long
id) {
Toast.makeText(Main.
this
,
"Item点击事件"
,Toast.LENGTH_SHORT).show();
}
});
}
private
class
ListAdapter
extends
BaseAdapter {
public
int
getCount() {
return
arr.length;
}
public
Object getItem(
int
position) {
return
position;
}
public
long
getItemId(
int
position) {
return
position;
}
public
View getView(
int
position, View view, ViewGroup parent) {
if
(view ==
null
) {
view = getLayoutInflater().inflate(R.layout.listview,
null
);
}
TextView name = (TextView) view.findViewById(R.id.wishname);
CheckBox ck = (CheckBox) view.findViewById(R.id.checkBox1);
if
(arr!=
null
)
{
name.setText(arr[position]);
name.setOnClickListener(
new
OnClickListener() {
@Override
public
void
onClick(View v) {
Toast.makeText(Main.
this
,
"TextView点击事件"
,Toast.LENGTH_SHORT).show();
}
});
ck.setOnCheckedChangeListener(
new
OnCheckedChangeListener() {
public
void
onCheckedChanged(CompoundButton buttonView,
boolean
isChecked) {
Toast.makeText(Main.
this
,
"CheckBox点击事件"
,Toast.LENGTH_SHORT).show();
}
});
}
return
view;
}}
}