- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试将一些数据加载到 ListFragment
中,但出现此错误:
05-07 00:05:30.533 625-625/com.myapp.android E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
我该如何处理?
这是我的文件,如果它们可以帮助的话:
主 Activity .java
public class MainActivity extends FragmentActivity {
private ViewPager viewPager;
private ViewpagerAdapter viewpagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
viewPager = (ViewPager) findViewById(R.id.pager);
viewpagerAdapter = new ViewpagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(viewpagerAdapter);
}
}
ListFrag.java
public class ListFrag extends ListFragment {
private DatabaseAdapter databaseAdapter;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_listagem, container, false);
return view;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
databaseAdapter = new DatabaseAdapter(getActivity());
databaseAdapter.open();
List<Foo> values = databaseAdapter.getAllFoobar();
//ArrayAdapter<Foo> adapter = new ArrayAdapter<Foo>(getActivity(), android.R.layout.simple_list_item_1, values);
//setListAdapter(adapter);
}
}
和fragment.xml
<FrameLayout 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"
tools:context="com.myapp.android.ListFrag">
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"></ListView>
</FrameLayout>
提前致谢!
最佳答案
java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
崩溃日志清楚地说明了问题。您需要更改 ListView
id 。 ListFragment
期望布局具有 ListView
id 作为 @android:id/list
android:id="@android:id/list"
如果您查看 ListFragment
源代码,它会使用 android.R.id.list
检查布局中的 ListView
ID
。如果 View 为 null,它将抛出 RuntimeException
View rawListView = root.findViewById(android.R.id.list);
if (!(rawListView instanceof ListView)) {
if (rawListView == null) {
throw new RuntimeException(
"Your content must have a ListView whose id attribute is " +
"'android.R.id.list'");
}
throw new RuntimeException(
"Content has view with id attribute 'android.R.id.list' "
+ "that is not a ListView class");
}
使用这个布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
关于android - 如何将数据加载到 ListFragment?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23506738/
我有一个包含项目类别的 ListView 。当我按下列表中的类别标题时,它将显示另一个 ListView ,其中包含所选类别中的项目。 我正在使用 ListFragment 执行此操作。我是否必须开始
首先我应该提到我使用 ActionBarSherlock 库来实现向后兼容性。 我有一个添加 ListFragment 的 Activity 当它第一次启动时。我有一个自定义 Loader我实现并遵循
谁能告诉我一个使用 CursorLoader 查询 SQLite 数据库并填充 ListFragment 的简单示例?下面的代码可以编译,但是当我运行它时,LogCat 告诉我“ListFrag”不能
我是 Android 开发新手,我正在尝试创建一个 ListFragment,它可以从 3 个 ArrayList 对象创建一个 ListView,每个对象包含 30 个字符串。每行将包含每个数组中的
我有一个具有两个 fragment (权重 3 和 2)线性布局的 Activity 。第一个 fragment 是一个列表 fragment 。它最初具有指定的权重高度,但是当列表变大时,它会变得更
我试图让我的 ListFragment 显示在我的 View 中,但是我对这段代码遇到了无穷无尽的问题,无法让它显示我的解析器的结果。我相信这很可能是我的 xml 文件的问题,我的代码中没有收到任何错
我有一个像这样的列表 fragment : private ArrayListimages; private View view; @Override public void onCreate(Bun
我已经向 ListFragment 添加了一个选项菜单,我需要在用户单击它时显示一个新的 ListFragment。这有什么问题吗?我对开始 fragment 的正确方法有点困惑.. 最佳答案 将事务
我是 android api 的新手,我在 .. 基础知识方面遇到了一些问题。我试图让列表正常工作,但列表显示了错误的文本: 每一行有两个 TextView(标题,副标题),这里是 xml:
我已经用头撞墙了大约一天了。我希望有人能提供帮助。 我的程序在异步任务中将一些 Json 加载并解析到对象数组中。这个异步任务是从我的 ListFragment 类调用的,数据在 onPostExec
我可以设法制作具有相同图标的列表 fragment 。但似乎我无法用不同的图标制作该列表。因此列表结果对于不同的项目列表将是不同的图标。我试试看。当我尝试构建它时。它没有显示错误。但是当我运行它时。它
我是 Android 开发的新手。我在使用 ListFragment 和自定义适配器时遇到问题。我的列表中没有对象。你能检查我的代码吗?如果我滚动到底部,您会看到一个对象,但随后会崩溃。 ListFr
我使用 Listfragmen,您的适配器在其中输出图像。 我需要在两列中显示图像。 我尝试放入 listView fragment ,但数据未显示。 我需要有两列来显示图像。
我正在尝试将一些数据加载到 ListFragment 中,但出现此错误: 05-07 00:05:30.533 625-625/com.myapp.android E/AndroidRuntime
我检查了有关 ListFragments 异步更新的其他答案,发现 notifyDataSetChanged() 方法不起作用的最常见问题是,开发人员倾向于覆盖初始适配器源,导致适配器丢失引用,因此不
我的应用程序中有两个列表 fragment 和一个 fragment 。我给你看第一个 fragment 。 应用程序启动,Asynctask 检索数据并将它们放入 arrayNews 中。我认为问题
我有一个 ListFragment,其中包含使用自定义 ArrayAdapter 填充的 Earthquake 对象列表。每个元素要么“突出显示”,要么不“突出显示”,具体取决于地震的震级是否高于某个
我是第一次使用 ListFragments。我想显示来自 sqlite 数据库的数据。 我的问题:我无法检索上下文。 我在扩展 ListFragment 的类中尝试了 this.getActivity
我有一个带有 ArrayAdapter 的 ListFragment 来显示对象列表。我想刷新 ListFragment 的内容。这些项目本身稍微改变了它们的文本,也改变了它们的顺序。我有一百多个项目
我有一个列表 fragment 显示我的自定义列表项,它由包含图像和文本等的相对布局组成。
我是一名优秀的程序员,十分优秀!