Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can add ListView items without using Adapter? too cumbersome for static array display

I'd like to implement ListView and each item have multiple tags like StackOverflow list (a kind of master-detail style view). Each tag in items is enumerated by tags string array.

The tags are no need to be changed/filtered when it first showed so that I think it does NOT need to use an adapter (an adapter is for binding between data model and view, right?). Moreover, I think using adapter in each item may cause performance issue in order to process additional bindings.

Is there any workaround to add ListView items without using Adapter?

For reference, in C#, listView.Items.Add("item1"); can display items simply.

like image 847
Youngjae Avatar asked May 08 '13 10:05

Youngjae


2 Answers

As @Android-Developer noted, it is impossible to add arrays to ListView without Adapter.

listViewTopics.setAdapter(new ArrayAdapter<Topic>(CurrentActivity.this, R.layout.item_tag, topics));

above single-line code is simplist way to show array items(topics in this example) to ListView.

like image 173
Youngjae Avatar answered Oct 12 '22 12:10

Youngjae


There is no option to create list with adapter. but yes you can use the default Array Adapter for list view.

List<String> values = new ArrayList<>();
values.add("Lesson 1.");
values.add("Lesson 2.");
values.add("Lesson 3.");
values.add("Lesson 4.");

ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
            (this, android.R.layout.simple_list_item_1, values);

listView.setAdapter(arrayAdapter);
like image 22
Hani Mehdi Avatar answered Oct 12 '22 14:10

Hani Mehdi