Is there anything bad with this code?
The thing is that the "test" is not displayed in ListView
.
Java:
private ListView namesListView;
private ArrayList<String> names;
private ArrayAdapter<String> namesAA;
...
namesListView = (ListView)findViewById(R.id.list);
names = new ArrayList<String>();
names.clear();
names.add(0, "test");
namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, names );
namesListView.setAdapter(namesAA);
...
XML:
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Have you tried this?
namesAA = new ArrayAdapter<String> ( this, android.R.layout.simple_list_item_1, android.R.id.text1, names );
By the way, why are you specifying the place of the item? You are clearing the arraylist so adding names.add("test");
is better, I think.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With