如何检索使用OnItemClick一个ListView的点击字符串? [英] How to retrieve the clicked string from a listview using OnItemClick?

查看:210
本文介绍了如何检索使用OnItemClick一个ListView的点击字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里有一些问题。它看起来简单,我一直寻找的解决方案。不幸的是,我无法找到任何东西。这是我的问题....我想要做的是得到从项目上单击的方式在ListView字符串显示。

这是我的列表视图:

   - 洛尔
- 喜
- 瓦乌

当我点击笑我想要得到的笑字符串.....

要我穿什么我的code在这里?

  LV =(ListView控件)findViewById(R.id.list_view);
lv.setOnItemClickListener(新OnItemClickListener()
{
 公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,长ARG3)
 {
    //意图newI =新意图(这一点,PDetail.class);
     意图newI =新意图(Create.this,PDetail.class);
     //字符串SD =((()ARG1).getText())的toString()。
     //newI.putExtra(\"x,ARG2);
     startActivity(newI);
    // db.getList(参数3); }});


解决方案

 公共无效onItemClick(适配器视图<>为arg0,ARG1观,诠释ARG2,长ARG3)
     {
         字符串数据=(字符串)arg0.getItemAtPosition(ARG2);
     }});

数据包含您的点击位置的数据。你想与做什么都。

I've got some problem here. It looks simple and i keep searching for its solution. Unfortunately, i cant find anything. This is my problem.... What i'm trying to do is to get the string showed in the listview from an On item click method.

This is my listview :

- lol
- hi
- waw

When i click "lol" i want to get the "lol" string.....

What should i put in my code here? :

lv = (ListView) findViewById(R.id.list_view);
lv.setOnItemClickListener(new OnItemClickListener()
{
 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
 {
    // Intent newI = new Intent(this,PDetail.class); 
     Intent newI = new Intent (Create.this, PDetail.class);
     //String sd = ((() arg1).getText()).toString();
     //newI.putExtra("x", arg2);
     startActivity (newI);
    // db.getList(arg3);

 }});

解决方案

 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3)
     {
         String data=(String)arg0.getItemAtPosition(arg2);


     }});

data contains your clicked position's data. Do what ever you want to do with that.

这篇关于如何检索使用OnItemClick一个ListView的点击字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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