Make whole line in a ListView clickable?

回眸只為那壹抹淺笑 提交于 2019-12-23 11:56:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!