Tüm satırları tutacak olan LinearLayout:
<?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:orientation="vertical" > <TableRow android:id="@+id/trHeader" android:layout_width="fill_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/tvAdiSoyadi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/kisi_adi_soyadi" /> <TextView android:id="@+id/tvAlani" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/kisi_alani" /> </TableRow> <ListView android:id="@+id/lvKisiler" android:layout_width="match_parent" android:layout_height="wrap_content" > </ListView> </LinearLayout>Her bir ListView item satırı:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" > <CheckBox android:id="@+id/cbKisiId" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:id="@+id/tvKisiId" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/rbKisi" android:layout_alignBottom="@+id/rbKisi" android:layout_toRightOf="@+id/rbKisi" android:text="ID" android:visibility="invisible" /> <TextView android:id="@+id/tvAdi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/tvKisiId" android:layout_alignBottom="@+id/tvKisiId" android:layout_marginLeft="15dp" android:layout_toRightOf="@+id/tvKisiId" android:text="Adi" /> <TextView android:id="@+id/tvAlani" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/rbKisi" android:layout_toRightOf="@+id/rbKisi" android:text="Alani" /> <TextView android:id="@+id/tvSoyadi" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignBaseline="@+id/tvAdi" android:layout_alignBottom="@+id/tvAdi" android:layout_marginLeft="10dp" android:layout_toRightOf="@+id/tvAdi" android:text="Soyadi" /> </RelativeLayout>SimpleCursorAdapter ile bağlanması:
ListView lvKisiler = (ListView) getActivity().findViewById(R.id.lvKisiler); Cursor crs = KisiDataSource.fetchAllKisiler(getActivity()); String[] fields = new String[] { VTHelper.COL_KISILER_ID, VTHelper.COL_KISILER_ADI, VTHelper.COL_KISILER_SOYADI, VTHelper.COL_KISILER_ALANI }; int[] toWidgets = new int[] { R.id.tvKisiId, R.id.tvAdi, R.id.tvSoyadi, R.id.tvAlani }; SimpleCursorAdapter sca = new SimpleCursorAdapter(getActivity(), R.layout.kisi_satir, crs, fields, toWidgets, 0); lvKisiler.setAdapter(sca);Custom CursorAdapter ile bağlanması:
CursorAdapter ca = new CursorAdapter(getActivity(), crs) { @Override public View newView(Context _ctx, Cursor _crs, ViewGroup _parent) { LayoutInflater inflater = LayoutInflater.from(_ctx); View v = inflater.inflate(R.layout.kisi_satir, _parent, false); bindView(v, _ctx, _crs); return v; } @Override public void bindView(View _view, Context _ctx, Cursor _crs) { CheckBox cbKisiId = (CheckBox)_view.findViewById(R.id.cbKisiId); TextView tvKisiId = (TextView)_view.findViewById(R.id.tvKisiId); tvKisiId.setText(_crs.getString(_crs.getColumnIndex(VTHelper.COL_KISILER_ID))); cbKisiId.setOnCheckedChangeListener(fk); TextView tvAdi = (TextView)_view.findViewById(R.id.tvAdi); tvAdi.setText(_crs.getString(_crs.getColumnIndex(VTHelper.COL_KISILER_ADI))); TextView tvSoyadi = (TextView)_view.findViewById(R.id.tvSoyadi); tvSoyadi.setText(_crs.getString(_crs.getColumnIndex(VTHelper.COL_KISILER_SOYADI))); TextView tvAlani= (TextView)_view.findViewById(R.id.tvAlani); tvAlani.setText(_crs.getString(_crs.getColumnIndex(VTHelper.COL_KISILER_ALANI))); } }; lvKisiler.setAdapter(ca);