Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android SimpleCursorAdapter:空的ListView_Android_Android Listfragment_Simplecursoradapter - Fatal编程技术网

Android SimpleCursorAdapter:空的ListView

Android SimpleCursorAdapter:空的ListView,android,android-listfragment,simplecursoradapter,Android,Android Listfragment,Simplecursoradapter,我正在将SimpleCursorAdapter与ListFragment一起使用,但显示的ListView为空(没有数据的项): 项目到搜索.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android

我正在将
SimpleCursorAdapter
ListFragment
一起使用,但显示的
ListView
为空(没有数据的项):

项目到搜索.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:orientation="horizontal"
    android:layout_gravity="center_vertical"
    android:weightSum="14">

    <TextView
        android:id="@+id/tv_ville_secteur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_weight="13"
        android:gravity="center_vertical"
        android:paddingTop="4dp"
        android:text="TextView"
        android:textColor="@android:color/holo_blue_bright"
        android:textSize="22dp" />

    <CheckBox
        android:id="@+id/cb_ville_secteur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="2dp"
        android:layout_weight="1"
        android:text="" />

</LinearLayout>

更改此选项

dataAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(), R.layout.fragment_recherhcer,db.getAllVillesAsCursor(),columns,to);

原因
TextView
带有id的
tv\u ville\u secteur
位于
item\u to\u search.xml

此构造函数在API级别11中被弃用。这个选项是 不鼓励,因为这会导致在 应用程序的UI线程,因此可能导致响应性差,甚至 应用程序没有响应错误。作为替代方案,使用 带有游标装入器的装入器管理器

不应使用上述方法

SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
Standard constructor.

这个函数返回的是什么?db.getAllVillesaScursors()public List getAllVilles()那么您误解了构造函数的属性,它将游标作为参数,因此
db.getAllVillesaScursors()应该返回游标。此外,您正在使用不推荐的constructor@Raghunandan是的,它们返回一个游标..public cursor getAllVillesascursors()@abdellahselasi,但请注意构造函数是deprecated@AbdellahSELASSI检查文件
<?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="horizontal"
    android:layout_gravity="center_vertical"
    android:weightSum="14">

    <TextView
        android:id="@+id/tv_ville_secteur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_weight="13"
        android:gravity="center_vertical"
        android:paddingTop="4dp"
        android:text="TextView"
        android:textColor="@android:color/holo_blue_bright"
        android:textSize="22dp" />

    <CheckBox
        android:id="@+id/cb_ville_secteur"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="2dp"
        android:layout_weight="1"
        android:text="" />

</LinearLayout>
dataAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(), R.layout.fragment_recherhcer,db.getAllVillesAsCursor(),columns,to);
dataAdapter = new SimpleCursorAdapter(getActivity().getBaseContext(), R.layout.item_to_search,db.getAllVillesAsCursor(),columns,to);
SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to)
SimpleCursorAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags)
Standard constructor.