-2

im a beginner in android/java programming and im trying to retrieve the element from a listview and put them in a textview.I know you can set text to a textview using settext but I dont know how to retrieve element from my listview(they are all strings) and put them in my textview

thank you

Phil_oneil
  • 267
  • 3
  • 11
  • get the adapter from the list view. The adapter gives you access to the data presented in the ListView – EJK Nov 05 '14 at 18:00
  • And how do I put adapter content in a textview? thanks – Phil_oneil Nov 05 '14 at 18:56
  • See my answer below. I extract the list content into a StingBuffer and then apply it to the textview by calling the setText method on the textView. – EJK Nov 05 '14 at 18:58

1 Answers1

1
StringBuffer allItems = new StringBuffer();

Adapter adapter = listView.getAdapter();
for (int i=0; i<adapter.getCount(); i++) {
    Object item = adapter.getItem(i);
    allItems.append(item.toString());
    allItems.append(", ");
}

textView.setText(allItems.toString());
EJK
  • 12,332
  • 3
  • 38
  • 55