本文是小编为大家收集整理的关于在Android ListView上使用SimpleAdapter添加onClick监听器的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我没有找到搜索的解决方案:(
我正在编程读取RSS源的应用程序.
我正在使用ListView,将屏幕标题和每个饲料的描述放入2 TextView.我意识到用一个简单的配方.
在我的项目中,我有2个课程:主动力和asynktask. 在MainActivity中,我执行读取RSS的ASYNCTASK并将它们放入适配器和ListView
中现在,如何在列表视图上添加单击侦听器,以将每个馈送打开到浏览器中?
我希望我已经正确解释了问题,我很抱歉我的英语非常糟糕! 谢谢大家.
ps:如果您需要我的一些代码,我会发布它.
推荐答案
在oncreate方法中,如果它是一个列表,所以您需要参考您的列表视图:
ListView lv = getListView();
然后添加单击侦听器,如下所示:
lv.setOnItemClickListener(new OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { //Open the browser here }
其他推荐答案
在列表视图上,您需要使用setOnitemclickListener
问题描述
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.
推荐答案
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 }
其他推荐答案
On your list view, you need to use setOnItemClickListener