Android:ListView没有出现或没有在Android中显示

时间:2015-12-05 05:23:28

标签: android android-listview android-sqlite

我正在尝试从listview实现填充SQLite,但是android突然listview没有出现在屏幕上。我的代码出了什么问题。

这是我的ListView布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@android:color/white">

    <ListView
            android:id="@+id/listview_AllPost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginTop="1dp"
            android:longClickable="true"></ListView>

</LinearLayout>

这是我的活动代码

listView = (ListView) findViewById(R.id.listview_AllPost);
        populateList();
 private void populateList() {

        descArray.clear();
        List<All_Post> allDesc = dbhelper.getAllDescriptions();
        for (All_Post all_Post : allDesc)
        {
            String strInspectorname = all_Post.getStringInspectorname();
            Log.e("strInspectorname "," = " + strInspectorname);
            descArray.add(all_Post);
        }

        if (adapter == null)
        {
            adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
            listView.setAdapter(adapter);
        }
        else if (adapter != null) {

            adapter.notifyDataSetChanged();
            adapter = new AllPostAdapter(this, R.layout.allpostlist, descArray);
            listView.setAdapter(adapter);
        }
    }

0 个答案:

没有答案