Reputation: 3
My app crashes when trying to use listview.
The xml (called activity_feedbackresults)
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textView1"
android:layout_centerHorizontal="true" >
</ListView>
the java
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_feedbackresults);
lv = (ListView) findViewById(R.id.listView1);
String[] arr = {"A","B","C"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.activity_feedbackresults, arr);
lv.setAdapter(adapter);
}
edit: logcat says ArrayAdapter You must supply a resource ID for a TextView. I don't understand what that means.
Upvotes: 0
Views: 20
Reputation: 7696
use the constructor that lets you enter textview id and give the id of your textview that you specified int the layout
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.activity_feedbackresults,
R.id.textviewId,
arr);
Upvotes: 1