求解:ListView有数据不显示问题
经跟踪测试,cursor已取得数据,并已用别的方法证实,问题是用listview显示不出cursor中的数据。
1.ListView的布局(文件名activity_logiin.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.ldl.gunxueqiu.app.LoginActivity">
<ListView
android:id="@+id/login_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
2.Item的布局文件(文件名listitem_priciple.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<textview android:id="@+id/list_Principle"
android:textColor="#ffff00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<textview android:id="@+id/list_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
3.代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
DatabaseHelper dbHelper = new DatabaseHelper(this);
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM Principle WHERE PrincipleClass ='91' ORDER BY ShowOrder", null);
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter (this,R.layout.listitem_principle, cursor,
new String[]{ "PrincipleContent","_id" },
new int[]{R.id.list_Principle,R.id.list_id},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
ListView lv = (ListView)findViewById(R.id.login_listView);
lv.setAdapter(listAdapter);
cursor.close();
}
4.库表结构
CREATE TABLE Principle ("_id" integer NOT NULL PRIMARY KEY,PrincipleClass text NOT NULL DEFAULT 00,PrincipleContent text,UpdateTime text,ShowOrder integer DEFAULT 0)
1.ListView的布局(文件名activity_logiin.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.ldl.gunxueqiu.app.LoginActivity">
<ListView
android:id="@+id/login_listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
2.Item的布局文件(文件名listitem_priciple.xml)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<textview android:id="@+id/list_Principle"
android:textColor="#ffff00"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<textview android:id="@+id/list_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
3.代码
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
DatabaseHelper dbHelper = new DatabaseHelper(this);
SQLiteDatabase db = dbHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT * FROM Principle WHERE PrincipleClass ='91' ORDER BY ShowOrder", null);
SimpleCursorAdapter listAdapter = new SimpleCursorAdapter (this,R.layout.listitem_principle, cursor,
new String[]{ "PrincipleContent","_id" },
new int[]{R.id.list_Principle,R.id.list_id},
CursorAdapter.FLAG_REGISTER_CONTENT_OBSERVER);
ListView lv = (ListView)findViewById(R.id.login_listView);
lv.setAdapter(listAdapter);
cursor.close();
}
4.库表结构
CREATE TABLE Principle ("_id" integer NOT NULL PRIMARY KEY,PrincipleClass text NOT NULL DEFAULT 00,PrincipleContent text,UpdateTime text,ShowOrder integer DEFAULT 0)
...全文
相关推荐
android listview显示数据库中内容
免费分享 供大家学习 listview显示数据库的某一列或某几列的内容
ScrollView嵌套ListView,解决显示不全的问题
ScrollView嵌套ListView,解决显示不全的问题
android读取sqlite数据库的数据并用listview显示
一个android读取sqlite数据库的数据并用listview显示demo,如有问题及时提醒。
android ListView向上滑动隐藏标题,下拉显示标题栏,完美解决滑动出现的空白问题。
向上滑动listview隐藏标题,向下滑动显示标题,完美解决滑动出现的空白问题。
解决scrollview嵌套listview显示不全的四种方法
重新测量listview高度,或者自定义listview


