ListView 具有正确的行数,但不显示文本
我在 tabhost 中创建了一个 ListActivity,该选项卡应该显示 sql 表中的所有记录。然而,当我单击该选项卡时,它显示了正确数量的行(分隔线),但没有任何其他数据/文本可供查看。所以基本上我得到一个空列表,并且我检查了数据库文件,数据就在那里!
我的表只有 _id 和 name 列。
这是我正在使用的代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor c;
ShowAdapter sa = new ShowAdapter(this);
sa.open();
c = sa.getSubscribedShows();
String[] from = new String[] { "name" };
int to[] = new int[] { R.id.text1 };
SimpleCursorAdapter shows = new SimpleCursorAdapter(this, R.layout.show_list, c, from, to);
setListAdapter(shows);
sa.close();
}
我的其他方法只是返回光标:
public Cursor getSubscribedShows(){
Cursor c = db.query(true, "shows", null, null, null, null, null, "name", null);
c.moveToFirst();
return c;
}
我的 XML 是:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:id="@+id/text1" >
</TextView>
你知道我做错了什么吗?
I have created a ListActivity inside a tabhost, and this tab is supposed to show all records from a sql table. When I click the tab however, it shows the right amount of rows (separation lines) but there's no data/text anything else to be seen. So basically I get an empty list, and I've checked the database file, the data is there!
My table only has the columns _id and name.
This is the code I'm using:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Cursor c;
ShowAdapter sa = new ShowAdapter(this);
sa.open();
c = sa.getSubscribedShows();
String[] from = new String[] { "name" };
int to[] = new int[] { R.id.text1 };
SimpleCursorAdapter shows = new SimpleCursorAdapter(this, R.layout.show_list, c, from, to);
setListAdapter(shows);
sa.close();
}
And my other method simply returns the cursor:
public Cursor getSubscribedShows(){
Cursor c = db.query(true, "shows", null, null, null, null, null, "name", null);
c.moveToFirst();
return c;
}
And my XML is:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:id="@+id/text1" >
</TextView>
Any ideas what I'm doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将
layout_height
属性更改为:并查看是否可以解决该问题
Change the
layout_height
propery to:and see if that fixes it