Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to bind a TableLayout with a ArrayAdapter?

Is it possible to bind a TableLayout with a ArrayAdapter?

like image 399
Manish Khot Avatar asked Feb 18 '11 09:02

Manish Khot


People also ask

When to use ArrayAdapter?

ArrayAdapter is more simple and commonly used Adapter in android. Whenever you have a list of single type of items which is backed by an array, you can use ArrayAdapter. For instance, list of phone contacts, countries or names.

How to create an 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

There is no such API in the framework. You can do it manually by querying the adapter yourself. Something like this:

int count = adapter.getCount();
for (int i = 0; i < count; i++) {
    tableLayout.addView(createTableRow(adapter.getItem(i)); // or tableLayout.addView(adapter.getView(i, null, tableLayout));
}
like image 131
Romain Guy Avatar answered Oct 15 '22 21:10

Romain Guy