Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Define list view with static elements on android in xml?

I want to create fragment which would display static menu as a set of rows in a list.

I like iOS method with static cells in a tableview. How can I achieve this in android (so no code is needed to define elements, just xml)

Is there any regular way to define static elements in xml next way

(pseudo-code)

list_view.xml  <List view>   - use element my_row with onclick=row1_clicked and title="row 1"   - use element my_row with onclick=row2_clicked and title="row 2"   - use element my_row with onclick=row3_clicked and title="row 3"   - use element my_row with onclick=row4_clicked and title="row 4" </List view>  my_row.xml  <My Row>   - text field (title should go here)   - on click (on click should go here) </My Row> 

So basically I want to "include" row in list and do it on xml level (without code).

like image 641
Nik Avatar asked Dec 13 '12 16:12

Nik


People also ask

What is the list view in android?

A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.

Which layout is used for list of views in Android?

Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.

How do I use Arrayadapter?

Go to app > res > layout > right-click > New > Layout Resource File and create a new layout file and name this file as item_view. xml and make the root element as a LinearLayout. This will contain a TextView that is used to display the array objects as output.


1 Answers

Unfortunately, list view definition via xml is forbidden. Mess with adapters is required instead.

like image 99
Nik Avatar answered Sep 29 '22 19:09

Nik