如何获得所选项目的索引,字符串列表视图中的android目的、视图、字符串、如何获得

由网友(陪你浪迹天涯)分享简介:我有这样一个ListView i have a listview like thiscompanyname symbolsamsung samonida ondtata ta...

我有这样一个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) 
    {
    }
});
阅读全文

相关推荐

最新文章