I am trying to get the text of the selected item and show it in a toast message. This is the code I wrote:
final ListView lv = (ListView)findViewById(R.id.firstflightlist); lv.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) { TextView c = (TextView) arg0.findViewById(arg1.getId()); String text = c.getText().toString(); Toast.makeText(getApplicationContext(), text, Toast.LENGTH_SHORT).show(); }});
A list is the only listview list. When I click on any item in the list, it always displays the first item in the list. What could be the reason for this? How to get selected element text?
source share