There is such an example of forming a GridView based on the transferred array of scalars.
http://startandroid.ru/ru/uroki/vse-uroki-spiskom/116-urok-57-gridview-i-ego-atributy.html
MainActivity.java:
public class MainActivity extends Activity { String[] data = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k"}; GridView gvMain; ArrayAdapter<String> adapter; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); adapter = new ArrayAdapter<String>(this, R.layout.item, R.id.tvText, data); gvMain = (GridView) findViewById(R.id.gvMain); gvMain.setAdapter(adapter); adjustGridView(); } private void adjustGridView() { gvMain.setNumColumns(3); } } item.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rect" android:orientation="vertical"> <TextView android:id="@+id/tvText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="40dp" android:textSize="20sp" android:text=""> </TextView> </LinearLayout> result:
and how to implement a more complex structure, where the array consists not of scalars, but arrays of 2 or more elements?
added:
I wanted to display a more complex fragment, for example item2.xml:
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rect" android:orientation="vertical"> <TextView android:id="@+id/tvText" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="40dp" android:textSize="20sp" android:text=""> </TextView> <TextView android:id="@+id/tvText2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center_vertical" android:minHeight="40dp" android:textSize="20sp" android:text=""> </TextView> </LinearLayout> How to connect the elements of the transmitted array with R.id.tvText and R.id.tvText2 ?

GridView. I personally do not understand what will mean aболее сложную структуру, где массив состоит не из скаляров, а массивов из 2х и более элементов- Vladyslav Matviienko