add onClick listener on Android ListView With SimpleAdapter

余生颓废 提交于 2019-12-19 04:51:45

问题


I didn't found the solution with the search :(

I'm programming an application for reading RSS feeds.
I'm using a listview for putting a screen title and description of every feed into 2 textview. I realized that with a SimpleAdapter.

In my project I have 2 classes: MainActivity and AsynkTask. In mainActivity I execute the asyncTask that reads RSS and puts them into the adapter and the listview

Now, how can I add a click listener on the listview for opening every feed into the browser?

I hope that I've explained correctly the problem and I'm sorry for my very bad english! Thanks to all.

PS: if you need some of my code i will post it.


回答1:


In the onCreate method of your MainActivity, if it's a ListActivity, you need to get a reference to your list view like so:

ListView lv = getListView();

Then add a click listener to it like so:

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) { 
  //Open the browser here
}



回答2:


On your list view, you need to use setOnItemClickListener



来源:https://stackoverflow.com/questions/8418255/add-onclick-listener-on-android-listview-with-simpleadapter

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