user3085838
user3085838

Reputation: 3

Can't seem to use listview properly

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

Answers (1)

EC84B4
EC84B4

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

Related Questions