求解:ListView有数据不显示问题

skykevin 2014-03-11 05:12:55
经跟踪测试,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)
...全文
314 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
哎,真难 2014-03-12
  • 打赏
  • 举报
回复
SimpleCursorAdapter好像只能读取一个值,你删_id看看,,,
绝世酱油瓶 2014-03-11
  • 打赏
  • 举报
回复
换SimpleAdapter试试呗

80,472

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧