0
一個ListView,id屬性'時,我有我的main.xml
這樣的:錯誤使用android.r.id.list`需要
<?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」?