SimpleCursorAdapter не заполняет мой ListView, без ошибок, просто ничего не происходит.SimpleCursorAdapter не заполняется ListView
Может ли кто-нибудь помочь мне найти ошибку?
1) Схема с ListView компонента (tab_frag1_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FF0000"
android:orientation="vertical" >
<ListView
android:id="@+id/lvVehicle"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
2) Схема для представления строки (vehicle_row.xml):
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1dip" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_arrow_right"
android:contentDescription="@null"
android:adjustViewBounds="true"
android:layout_marginRight="3dip"
android:layout_gravity="center_vertical" />
<TextView
android:id="@+id/plate"
style="@style/vehicleDefaultFont.plate"
android:text="@string/label_text_view" />
<TextView
android:id="@+id/hyphen"
android:text="@string/label_hyphen" />
<TextView
android:id="@+id/model"
android:text="@string/label_text_view" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="1dip" >
<TextView
android:id="@+id/driver"
style="@style/vehicleDefaultFont.driver"
android:layout_span="4"
android:text="@string/label_text_view" />
</TableRow>
</TableLayout>
3) Фрагмент Класс:
public class Tab1Fragment extends Fragment {
String TAG = getClass().getName();
private VehicleDbAdapter dbHelper;
private SimpleCursorAdapter dataAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.tab_frag1_layout, container, false);
dbHelper = new VehicleDbAdapter(getActivity());
dbHelper.open();
dbHelper.deleteAllVehicles();
dbHelper.insertVehicles();
Cursor cursor = dbHelper.fetchAllVehicles();
if(cursor != null && cursor.getCount() > 0) {
String[] columns = new String[] {
VehicleDbAdapter.KEY_MODEL,
VehicleDbAdapter.KEY_PLATE,
VehicleDbAdapter.KEY_DRIVER
};
int[] to = new int[] {
R.id.model,
R.id.plate,
R.id.driver,
};
dataAdapter = new SimpleCursorAdapter(
view.getContext(),
R.layout.vehicle_row,
cursor,
columns,
to,
0);
ListView listView = (ListView) view.findViewById(R.id.lvVehicle);
listView.setAdapter(dataAdapter);
Log.i(TAG, "Cursor = " + cursor.getCount());
} else {
Log.i(TAG, "Cursor = " + cursor.getCount());
}
return view;
}
}
Любопытно:
Мой курсор содержит поле _id.
Я дважды проверил свой курсор и у него 7 строк.
07-21 01: 30: 22,215: I/Cursor = 7
Я попытался с помощью макета родовому андроида макет списка, но ничего не делает :(
dataAdapter = new SimpleCursorAdapter(
view.getContext(),
android.R.layout.simple_list_item_1,
cursor,
columns,
to,
0);
Любая помощь приветствуется .
Вы - парень, lol. Спасибо тебе, брух! – vinidog
@vinidog no problem, man – Vikram