如何获得它被点击的android一个ListView项的价值? [英] How to get the value of a Listview item which is clicked in android?

查看:81
本文介绍了如何获得它被点击的android一个ListView项的价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的低于code访问ListView项值转换成字符串,并在警报显示呢?

 的ListView拍= getListView();
shot.setOnItemClickListener(本);

公共无效onItemClick(适配器视图<>为arg0,查看ARG1,INT ARG2,长ARG3){

    字符串s = arg1.getContext()的toString()。
    AlertDialog.Builder alertbox =新AlertDialog.Builder(本);

    //设置为显示该消息
    alertbox.setMessage(S) -  .show();
}
 

解决方案

也许这个例子可以帮助你。

  lv.setOnItemClickListener(新OnItemClickListener(){
    公共无效onItemClick(适配器视图<>母公司视图中查看,
        INT位置,长的id){
      //单击时,显示出与TextView的文字敬酒
      Toast.makeText(getApplicationContext(),((TextView的)视图).getText()
          Toast.LENGTH_SHORT).show();
    }
  });
 

<一个href="http://developer.android.com/intl/zh-TW/resources/tutorials/views/hello-listview.html">http://developer.android.com/intl/zh-TW/resources/tutorials/views/hello-listview.html

I have this below code access the ListView item value into string and display it in alert?

ListView shot = getListView();
shot.setOnItemClickListener(this);

public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

    String S = arg1.getContext().toString();
    AlertDialog.Builder alertbox = new AlertDialog.Builder(this);

    // set the message to display
    alertbox.setMessage(S).show();    
}

解决方案

maybe this example will help you

  lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view,
        int position, long id) {
      // When clicked, show a toast with the TextView text
      Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
          Toast.LENGTH_SHORT).show();
    }
  });

http://developer.android.com/intl/zh-TW/resources/tutorials/views/hello-listview.html

这篇关于如何获得它被点击的android一个ListView项的价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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