如何获得所选项目的索引,字符串列表视图中的android [英] how to get the index and string of the selected item in listview in android

查看:167
本文介绍了如何获得所选项目的索引,字符串列表视图中的android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样一个ListView

i have a listview like this

companyname              symbol

samsung                  sam
onida                    ond
tata                     ta
.                         .
.                         .
.                         .

所以我想选择的项目,该指数也字符串所选择的项目(即,SAM(或)OND(或)TA)。所以请告诉我怎么去选择的项目和字符串的索引也。

so i want to get the index of the selected item and also string of the selected item(i.e.,sam(or)ond(or)ta) .So please tell me how to get the index of the selected item and string also .

感谢你在前进

推荐答案

使用这种方式

listview.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() 
{
    public void onItemSelected(AdapterView parentView, View childView, int position, long id) 
    {
        String text = ((TextView)childView.getText()).toString();
        //The above text variable has the text value of selected item
        // position will reflect the index of selected item
    }
    public void onNothingSelected(AdapterView parentView) 
    {
    }
});

这篇关于如何获得所选项目的索引,字符串列表视图中的android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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