android listview 获取所选项目 [英] android listview get selected item

查看:18
本文介绍了android listview 获取所选项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 android 新手,我有一个代码,其中我在列表视图中放置了按钮.我的清单是..

I am new to android, I have a code in which I have placed buttons in list view. My list is as..

Number | Name | ID (visibility = gone) | Level | button1 | button2

按钮 1 和按钮 2 的功能不同.我已经在按钮上应用了侦听器,但是当我尝试从列表中获取 ID 时,它总是向我显示最后一个 ID.

Function is different in button 1 and button 2 case. I have applied listeners on buttons but when I try to get the ID from list it always shows me the last id.

如何知道点击了哪个按钮,相关字段的名称和id.

How to know which button was clicked, name and id of related field.

我在 getView(...) 函数中的按钮上放置了按钮和监听器.

I have placed buttons and listener on buttons in getView(...) function.

推荐答案

final ListView lv = (ListView) findViewById(R.id.ListView01);

lv.setOnItemClickListener(new OnItemClickListener() {
      public void onItemClick(AdapterView<?> myAdapter, View myView, int myItemInt, long mylng) {
        String selectedFromList =(String) (lv.getItemAtPosition(myItemInt));

      }                 
});

希望这能解决您的问题.

I hope this fixes your problem.

这篇关于android listview 获取所选项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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