/ / Chcę ustawić wartości ArrayList w ListView - android, arraylist, tablelayout

Chcę ustawić wartości ArrayList w ListView - Android, arraylist, tablelayout

Pracuję nad ArrayList. Chcę wyświetlić ArrayList w ListView, nie mam pojęcia o użyciu ArrayList w ListView.

wprowadź opis obrazu tutaj

Na obrazie "Cumputer Science" jest tematem, powinien on być pod subem i inne wartości również podlegają każdemu z nich.

//układ

      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:background="@drawable/login"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout android:layout_weight="1" android:layout_height="fill_parent"   android:layout_width="fill_parent"
android:layout_marginTop="175dp" android:orientation="horizontal" android:background="@android:color/darker_gray"
android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginBottom="20dp">

<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Sub" android:layout_marginLeft="5dp"/>

<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Mon" android:layout_marginLeft="20dp"/>

<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Tue" android:layout_marginLeft="23dp"/>

<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Wed" android:layout_marginLeft="23dp"/>

<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Thu" android:layout_marginLeft="23dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="match_parent"
android:textSize="16dp" android:text="Fri" android:layout_marginLeft="23dp"    android:layout_marginRight="2dp"/>

</LinearLayout>
<LinearLayout android:layout_weight="1" android:layout_height="fill_parent" android:layout_width="fill_parent"
android:layout_marginLeft="5dp">

<ListView android:layout_height="match_parent"  android:layout_width="match_parent" android:id="@+id/getAttdnce_lv">

</ListView>

</LinearLayout>


</LinearLayout>

Odpowiedzi:

1 dla odpowiedzi № 1

Spróbuj użyć TableLayout, a następnie dynamicznie twórz wiersze zgodnie z potrzebami.


0 dla odpowiedzi nr 2
public class MainActivity extends Activity {
public static final String[] Subject = new String[] { "Maths","Computer", "english"};
private ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
lv=(ListView)findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this,  android.R.layout.simple_list_item_1, Subject);
lv.setAdapter(adapter);
}


}