我有一列与适配器一起工作的列,它工作正常。现在我试图将它分成两列,并且我收到了例外情况。Android - 尝试显示多列列表时出现异常
我下面这个教程,这似乎是最简单的:http://www.heikkitoivonen.net/blog/2009/02/15/multicolumn-listview-in-android/
我有我宣布这样一个Java活动:
public class SeeAllQuestionsActivity extends ListActivity
,这里是一些代码:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
FlurryAgent.onStartSession(this, "8CA5LTZ5M73EG8R35SXG");
setContentView(R.layout.all_question_page);
...
这里是all_question_page 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"
android:padding="3px"
>
<include android:id="@+id/header"
layout="@layout/header"
android:layout_height="wrap_content"
android:layout_width="fill_parent"/>
<TextView
android:id="@+id/loading_questions"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Some prompt text."
android:textSize="10sp"
/>
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="@+id/label"
android:textSize="20px" >
</ListView>
</LinearLayout>
顺便说一句,如果有人能向我引用列表ID讲解两种语法差异性之探源,这将是巨大的:
android:id="@android:id/list"
android:id="@+id/list"
仅供参考,这些都不是为我工作:)
这里是questions_list.xml布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/TRAIN_CELL"
android:layout_width="50dip"
android:layout_height="wrap_content"/>
<TextView android:id="@+id/FROM_CELL"
android:layout_width="70dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
<TextView android:id="@+id/TO_CELL"
android:layout_width="60dip"
android:layout_height="wrap_content" android:layout_weight="1"/>
</LinearLayout>
当我在模拟器上运行它,它运行时异常抱怨这一行崩溃:setContentView(R.layout.all_question_page);
和错误是:
java.lang.RuntimeException:
Your content must have a ListView whose id attribute is 'android.R.id.list'
请帮帮忙,我非常卡住
谢谢!!
当您在代码中设置列表时,您是否为适配器和相应的R.id设置了整数数组。TRAIN_CELL,R.id.FROM_CELL和R.id.TO_CELL? – 2012-07-24 00:37:11
@HowardHodson我在setContentView调用之前没有设置它。我应该这样做吗?我没有注意到这个教程。 – Genadinik 2012-07-24 00:39:10