问题
I have some problems with my ListView. At fist I build my project for android v2.2. No I build the same one in v2.1. My Problem is now, that in my listview no longer the whole line is clickable but only the text is clickable. How could I make my whole line clickable again?
Alex
Edit: I use a simple adapter.
Edit2: My code:
setListAdapter (new ArrayAdapter <String> (myEvents.this, R.layout.list_item, titleList));
ListView list = getListView();
list.setTextFilterEnabled(true);
list.setOnItemClickListener(new OnItemClickListener(){
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
// here is an alert dialog
}
}
回答1:
You can do something like this...
override the getview of the simple adapter like shown in this link.
In the adapter..
View getView(......)
{
// set the tag of the text view object
textView.setTag(data);
textView.setOnClickListner(myOnClick);
}
Member on click listener.
public OnClick myOnClick = new Onclick(
void onclick(View v)
{
Object data = view.getTag();
// do something based on the data..
}
);
I hope it helps...
来源:https://stackoverflow.com/questions/8761726/make-whole-line-in-a-listview-clickable