使用 SimpleAdapter 在 Android ListView 上添加 onClick 侦听器 [英] add onClick listener on Android ListView With SimpleAdapter

查看:16
本文介绍了使用 SimpleAdapter 在 Android ListView 上添加 onClick 侦听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我没有通过搜索找到解决方案:(

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

我正在编写一个用于阅读 RSS 提要的应用程序.
我正在使用列表视图将每个提要的屏幕标题和描述放入 2 个文本视图中.我通过 SimpleAdapter 意识到了这一点.

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.

在我的项目中,我有 2 个类:MainActivity 和 AsynkTask.在 mainActivity 中,我执行 asyncTask 读取 RSS 并将它们放入适配器和列表视图

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:如果你需要我的一些代码,我会发布它.

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

推荐答案

在 MainActivity 的 onCreate 方法中,如果是 ListActivity,则需要像这样获取对列表视图的引用:

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
}

这篇关于使用 SimpleAdapter 在 Android ListView 上添加 onClick 侦听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆