Can you add ListView items without using an adapter? too cumbersome to display a static array

I would like to implement a ListView, and each element has several tags, such as a StackOverflow list (a style view of the master detail style). Each tag in the elements is listed by tags string array.

Tags do not need to be changed / filtered when they are first shown, so I think that you do NOT need to use an adapter (the adapter is designed to bind between the data model and the view, right?). Moreover, I think that using an adapter in each element can cause performance problems to handle additional bindings.

Is there a workaround to add ListView items without using an Adapter ?

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

+4
source share
3 answers

As @Android developer pointed out, it's not possible to add arrays to a ListView without an Adapter .

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

the above single-line code is a simplified way to display array elements ( topics in this example) to a ListView .

+3
source

Try it.

In string.xml do it first ..

 <string-array name="Entries"> <item>Item 1</item> <item>Item 2</item> <item>Item 3</item> </string-array> 

Then do it in your ListView in xml ..

 <ListView android:layout_width="match_parent" android:layout_height="wrap_content" android:entries="@array/Entries"></ListView> 
0
source

There is no way to create a list with an adapter. but yes, you can use the default Array adapter to view the list.

 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); 
0
source

Source: https://habr.com/ru/post/1479706/


All Articles