0
tI've ListActivity。 ListActivity的布局是ListView - SimpleCursorAdapter - @android:id/empty
<ListView android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawSelectorOnTop="false"
/>
<TextView android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="No elements found"
android:gravity="center"
/>
ListActivity与CursorAdapter相关。
当用户选择列表中的一个项目,我开始另一个活动以显示所选项目的详细信息:
Intent intent = new Intent(MyListActivity.this, DetailActivity.class);
startActivity(intent);
一切工作正常,当用户选择列表中的项目除外。在开始“详细活动”之前,显示带有“@android:id/empty”标识的textview的“No elements found”消息。
这是因为我关闭了onPause方法中的游标。但我认为我必须关闭它,因为我要离开目前的活动。
@Override
protected void onPause()
{
super.onPause();
if (this.cursor != null)
this.cursor.close();
this.db.close();
}
什么我可以做,如果我不希望看到TextView的“@android:ID /空”当我离开当前的活动?
谢谢
感谢您的回答。确实如果我让系统为我管理光标,它就是完美的。它的工作原理是,当细节活动打开时,光标似乎没有关闭。但我不明白为什么当我管理光标时它不能正常工作。 – Eduardo 2012-07-10 08:26:37
发生这种情况是因为在您的新活动启动之前“onPause”正在执行。如果你不想让系统处理它(我不明白你为什么不这样做),你的另一种选择是将'this.cursor.close()'和'this.db.close'移动到'onStop()'方法。从文档:“当用户不再看到活动时调用”。这应该可以解决你的问题。 – Barak 2012-07-10 12:49:52