- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我刚刚开始为我的应用程序构建一个非常简单的得分屏幕,但似乎没有发生任何事情,我不明白为什么。
列表 Activity :
public class HighScoresActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.high_scores);
ScoresDatabase db = new ScoresDatabase(this);
Cursor data = db.getHighScores();
ListAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, data, new String[] { "level" }, new int[] { R.id.level_text });
setListAdapter(adapter);
data.close();
db.close();
}
}
high_scores.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:text="Text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/level_text"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
没有任何错误消息,什么也没有发生。也不是光标是空白的,当我测试adapter.getCount()方法时,它返回~30,这与预期完全一致。
我认为所有函数名称都非常直观,但如果您需要任何说明,请询问。
非常感谢任何帮助
最佳答案
data.close(); // DON'T DO THIS
来自 Cursor.close() 的文档...
Closes the Cursor, releasing all of its resources and making it completely invalid. Unlike deactivate() a call to requery() will not make the Cursor valid again.
ListView
的 Adapter
必须有一个“Activity ”Cursor
,否则它将无法工作。另外,关闭数据库并不总是一件好事,并且在某些情况下可能会产生不利影响(根据我的经验) - 我不确定这是否也会导致问题。
编辑:根据 Dave Newton 的评论并检查了我自己的一些代码,问题在于在 Cursor 上调用
还有数据库。简而言之,删除以下行...close()
data.close();
db.close();
关于java - 使用 SimpleCursorAdapter + Sqlite 似乎不适用于 ListActivity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7923080/
在 Android 应用程序中,“ListActivity”可以作为主要 Activity 吗? 最佳答案 是的,您可以使用 ListActivity 作为您应用的主要 Activity 。只需将其定
我正在尝试创建一个 ListActivity,其行包含文本和图像。但它只显示一行的值,其他行的图像和文本是不可见的。当我调试代码时,它们的值不为空。但它显示行,但除了第一行之外,在布局上不显示这些文本
我有一个基本的 ListActivity 和一些假测试数据。当我运行该应用程序时,它立即崩溃。我尝试调试但没有得到任何反馈。它在说开始后就停止了: Intent 。 public class Pers
如何制作一个包含图片和摘要(项目列表文本下的文本)的列表,它对项目的描述很少。 我的代码制作了一个包含图片的列表。如何添加摘要? Activity 类别: public clas
当我尝试设置 listAdapter 或适配器(#setListAdapter(), #getListView().setAdapter())时,它不显示。当我尝试单独设置 ListView 时,它工
我需要在同一 Activity 中插入来自两个列表(从游标填充)的数据。 布局必须是: -TextView1-从 table1 游标列表 -TextView2-从 table2 游标列表 这可能吗?
鉴于我下面的 xml 文件,当我的对象列表不为空时,我想显示 ListView,当我的列表为空时,我想显示 ViewStub。我可以让它工作,但每当我改变屏幕方向时,我都会丢失我添加到列表中的新数据。
我的 Android 应用程序中有一个运行良好的 ListActivity。直到我决定使用加速度计添加滚动功能。 这是我的代码: package be.pxl.minecraftguide; impo
我有以下 ListActivity: public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanc
有人知道使用 CursorAdapter 的简单示例吗?这是我现在正在做的事情,它因 RuntimeException 而崩溃。鉴于我是新手并且找不到使用 Cursor 的 ListView 的任何简
我正在使用 ListActivity 来显示图标化列表(使用 BaseAdapter 的自定义实现)。它没有正确地重新加载数据。当我更改适配器的内容并通知列表时,似乎旧数据绘制在新数据之上,直到发生滚
我在使用带有自定义适配器的 ListActivity 时遇到了问题。这是适配器代码: public class CustomRowAdapter extends BaseAdapter { p
所以,我在这里有我的 onCreate 方法,用于使用用户安装的应用程序填充 ListView。这需要很长时间才能完成,我试图弄清楚在哪里创建一个新线程来完成一些繁重的工作,以便我可以在加载列表时显示
我可以在从外部 XML 资源加载内容后更新 ListActivity 吗:/? SUB() 是 ListActivity Main() -> opening: SUB() -> updating fr
我正在构建一个小型应用程序,我想在新数据到达时自动更新它。 根据我阅读的 android 文档,我认为因为我使用的是较新的技术,所以会在后台为我创建一个 ContentObserver,并且我会自动调
我有一个显示玩家信息的 Activity 。这部分工作正常。 (我使用了适配器)。但是,我应该将检测某行何时被单击的代码放在哪里? PlayersActivity.java package com.d
是否可以将 ListActivity 的页眉和页脚设置为固定在顶部和底部,这样只有内容(列表)在滚动,而不是页眉和页脚? 我都是这样设置的: View header = getLayoutInflat
我正在使用兼容性库将现有应用程序转换为 Fragments API。我读到您应该更新扩展 Activity 的类以现在使用 FragmentActivity。这对大多数情况都很好,但是扩展 ListA
我有一个 super 简单的 ActivityList,比如一个包含所有国家/地区的 scoll 列表。现在,我想按大陆对国家进行分组: 阿兹亚 中国 印度 欧洲 法国 希腊 Android 联系人应
我有一个实现 Runnable 的列表 Activity ,因此我的数据获取是通过进度条完成的。数据是从网络服务中提取的。现在,我要获取所有用户,但我想对其进行更改,以便它一次检索用户一页,而不是一次
我是一名优秀的程序员,十分优秀!