Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: None  |  size: 1.58 KB  |  hits: 18  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to extract the text from the selected item on the listView
  2. ListView lv = (ListView)findViewById(R.id.listView1);
  3.     lv.setAdapter(new ArrayAdapter<Country>(
  4.             this,R.layout.list_black_text,R.id.list_content, values));
  5.  
  6.  
  7.     lv.setOnItemClickListener(new OnItemClickListener() {
  8.         public void onItemClick(AdapterView<?> parent, View view,
  9.             int position, long id) {
  10. ??????
  11.     }});
  12.         }
  13.        
  14. ClassCastException: android.widget.LinearLayout
  15.        
  16. ListView lv = (ListView)findViewById(R.id.listView1);
  17.     lv.setAdapter(new ArrayAdapter<Country>(
  18.             this,R.layout.list_black_text,R.id.list_content, values));
  19.  
  20.     lv.setOnItemClickListener(new OnItemClickListener() {
  21.         public void onItemClick(AdapterView<?> parent, View view,
  22.             int position, long id) {
  23.             TextView textView = (TextView) view.findViewById(R.id.list_content);
  24.             String text = textView.getText().toString();
  25.             System.out.println("Choosen Country = : " + text);
  26.  
  27.     }});
  28.        
  29. String selectedFromList = (lv.getItemAtPosition(position));
  30.        
  31. String s = list.get(position);
  32.        
  33. String s = values.get(position).getCountryName();
  34. Log.e("LISTVIEW", "selected item text = "+s);
  35.  
  36.   or
  37.  
  38. String s = values.get(position).toString();
  39. Log.e("LISTVIEW", "selected item text = "+s);
  40.        
  41. public void onItemClick(AdapterView<?> parent, View view,
  42.         int position, long id) {
  43.         TextView textView = (TextView) view.findViewById(R.id.list_content);
  44.         String text = lv.get(position).tostring().trim();
  45.         System.out.println("Choosen Country = : " + text);
  46.  
  47. }});