错误是什么意思?
package conde.app;
import android.app.Activity;
import android.os.Bundle;
import android.widget.*;
import android.app.*;
import android.view.*;
import android.util.*;
import android.database.sqlite.*;
import android.content.*;
import java.util.*;
import android.database.*;
import android.R.*;
public class MKBApplication extends Activity
{
/** Called when the activity is first created. */
Button aBtn = (Button) findViewById(R.id.addBtn);
Button dBtn = (Button) findViewById(R.id.deleteBtn);
private GroceryDataSource datasource;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
datasource = new GroceryDataSource(this);
datasource.open();
List<Grocery> values = datasource.getAllGroceryItems();
ArrayAdapter<Grocery> adapter = new ArrayAdapter<Grocery>(this,
android.R.layout.simple_list_item_2, values);
setListAdapter(adapter);
}
public void onClick(View view) {
@SuppressWarnings("unchecked")
ArrayAdapter<Grocery> adapter = (ArrayAdapter<Grocery>) getListAdapter();
Grocery grocery = null;
switch(view.getId()){
case R.id.addBtn:
String[] name = new String[] { "Pork", "Chicken", "Onion" };
String[] quantity = new String[] { "1/2 kilo", "3 kilos", "1 kilo" };
int nextInt = new Random().nextInt(3);
grocery = datasource.createGroceryItem(name[nextInt], quantity[nextInt]);
adapter.add(grocery);
break;
case R.id.deleteBtn:
if (getListAdapter().getCount() > 0) {
grocery = (Grocery) getListAdapter().getItem(0);
datasource.deleteGroceryItem(grocery);
adapter.remove(grocery);
}
break;
}
adapter.notifyDataSetChanged();
}
@Override
protected void onResume() {
datasource.open();
super.onResume();
}
@Override
protected void onPause() {
datasource.close();
super.onPause();
}
}
这是我的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:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Hello World, MKBApplication"
/>
<Button
android:id="@+id/addBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="ADD"
/>
<Button
android:id="@+id/deleteBtn"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="DELETE"
/>
<ListView
android:id="@android:id=list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
答案 0 :(得分:0)
<ListView
android:id="@android:id=list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
应该是
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>