Пожалуйста, помогите мне с этим кодом - я в основном перебираю книгу и пытаюсь создать примеры самостоятельно, но не могу обойти эту ошибку. Я проверил свой LogCat, и он говорит: «java.lang.RuntimeException: у вашего контента должен быть ListView, атрибут id которого равен« android.R.id.list »». Я знаю, что, возможно, есть какая-то небольшая деталь, которую я опускаю, что является причиной этого, но я не могу это понять - это почти точная копия примера работающей программы, приведенного в книге. Я пытаюсь создать простой ArrayAdapter и добавить в него фиктивный список. Вот три файла, представляющих интерес:
package com.example.bwett.SimpleList;
import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class SimpleList extends ListActivity {
String[] item = {"Item1", "Item2", "Item3", "Item4",
"Item5", "Item6", "Item7", "Item8"};
TextView mainLabel;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
setListAdapter(new ArrayAdapter<String> (this,
R.layout.row,
R.id.label,
item));
mainLabel = (TextView)findViewById(R.id.mainLabel);
}
public void onListItemClick(ListView parent, View v,
int position, long id){
mainLabel.setText(item[position]);
}
}
main.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:id="@+id/mainLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:drawSelectorOnTop="false"/>
</LinearLayout>
ROW.XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/ok"
android:layout_width="22px"
android:layout_height="fill_parent"
android:padding="2px"
android:src="@drawable/icon"/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:textSize="44sp"/>
</LinearLayout>