我有我main.xml
这样的:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView android:id="@+id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
和row.xml
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<ImageView
android:id="@+id/icon"
android:padding="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/accept"
/>
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="40sp"
/>
</LinearLayout>
我的程序是这样做的(我从书中举了一个例子):
public class FancyListActivity extends ListActivity {
private TextView selection;
private static final String[] items= {"lorem", "ipsum","dolor","sit", "amet",
"consectetuer", "adipiscing", "elit", "morbi", "vel", "ligula", "vitae", "arcu",
"aliquet", "mollis", "etiam", "vel", "erat", "placerat", "ante",
"porttitor","sodales","pellentesque","augue", "purus"};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.row);
setListAdapter(new ArrayAdapter<String>(this, R.layout.row, R.id.label, items));
selection= (TextView)findViewById(R.id.label);
}
public void onListItemClick(ListView parent, View v, int position, long id){
selection.setText(items[position]);
}
}
但现在我得到这个错误:
Your content must have a ListView whose id attribute is 'android.R.id.list'
如果我有我的 android:id="@+id/list",为什么会出现此错误?