itzick binder
itzick binder

Reputation: 562

Adding Items to ListView on android

I have a list view on this XML:

<ListView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/listView"
    android:layout_below="@+id/textView"
    android:layout_centerHorizontal="true"
    android:layout_above="@+id/txtMsg" />

I want to add items to the list view in my code. This is my code:

ListView mesList = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> adapter;
if(messages.size()>0) {
    adapter = new ArrayAdapter<String>(this, android.R.layout.activity_list_item, messages);
}

messages is an ArrayList of String and is not empty. For some reason the list view is empty on the screen. What should I put instead of android.R.layout.activity_list_item? I think this is my problem. Thank you in advance!

Upvotes: 0

Views: 64

Answers (1)

user3279053
user3279053

Reputation: 187

set adapter of listview mesList.setAdapter(adapter); adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, messages);

Upvotes: 1

Related Questions