How to extract the text from the selected item on the listView

后端 未结 14 2576
轻奢々
轻奢々 2020-11-28 07:55

I have a listview with some items. I would like to get the text from the selected item.

Here is my list adapter and the onItemClickListener:

ListView         


        
14条回答
  •  生来不讨喜
    2020-11-28 08:40

    It will definitly works!Hope you Satisfied!

    ListView lv=(ListView)findViewById(R.id.listView1);
    
    lv.setOnItemClickListener(new OnItemClickListener() {
    
        @Override
        public void onItemClick(AdapterView arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            String text = (String) lv.getItemAtPosition(arg2);
            Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show();
    
        }
    });
    

提交回复
热议问题