Can i get onClickListener for this list listed by CustomAdapter?

无人久伴 提交于 2019-12-25 03:58:11

问题


I have listed a list with custom adapter to display different images in each list item and succeeded. Now i need to add a onitemclick listener for that list. Unable to access the id because the list id is - "@+id/android:list". Unable to identify this id.

Any ideas please share. You will get some more idea when you see this below link

Click here for the example i tried.


回答1:


In the given example, the ListActivity is extended in CustomAdapterActivity.java

so its simple to get Click events of the list items by writing list item click listener

and to write onClickListener you need to do

like this in that class.

**

public class Test extends ListActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        ListView lv = getListView();
        lv.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

            }
        });
    }
    @Override
    protected void onListItemClick(ListView l, View v, int position, long id) {
        // TODO Auto-generated method stub
        super.onListItemClick(l, v, position, id);
    }

    }

**

And To Know More and Learn About LIST VIEW in Android you can view this : http://www.vogella.de/articles/AndroidListView/article.html#overview_listview



来源:https://stackoverflow.com/questions/7753765/can-i-get-onclicklistener-for-this-list-listed-by-customadapter

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