我有一列與適配器一起工作的列,它工作正常。現在我試圖將它分成兩列,並且我收到了例外情況。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