大家好我需要一些幫助解決我的問題。我想在database
中顯示所有數據。但是,當我試圖表明,我得到這樣的日誌目錄的錯誤:你的內容必須有一個ListView
其id屬性是android.R.id.list
錯誤android:你的內容必須有一個ListView的id屬性是android.R.id.list
這是我在查詢DBHelper.java
public Cursor getAll() {
SQLiteDatabase db = getReadableDatabase();
Cursor cur = db.query(TableName, new String[]{ID, LATITUDE, LONGITUDE,
RADIUS,
ALAMAT, KONTEKS_TUGAS}, null, null, null, null, null);
db.close();
return cur;
}
我在視圖代碼
public class readReminder extends ListActivity {
DBHelper helper;
ListView taskList;
ArrayList<Task> listArr;
listAdapter listadapt;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.read_task);
taskList = (ListView) findViewById(android.R.layout.simple_list_item_1);
helper = new DBHelper(this);
listArr = new ArrayList<Task>();
Cursor cur = helper.getAll();
if(cur.moveToFirst()) {
do {
ArrayList temp = new ArrayList();
temp.add(String.valueOf(cur.getString(5)).toString());
temp.add(String.valueOf(cur.getString(6)).toString());
listArr.addAll(temp);
} while(cur.moveToNext());
}
cur.close();
listadapt = new listAdapter(getApplicationContext(), listArr);
taskList.setAdapter(listadapt);
}}
listAdapter.java
public class listAdapter extends BaseAdapter {
Context konteks;
ArrayList<Task> data;
public listAdapter(Context context, ArrayList<Task> data) {
this.konteks = context;
this.data = data;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return this.data.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return null;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
LayoutInflater inflater = (LayoutInflater)
konteks.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.txt_view, null);
TextView txt = (TextView) view.findViewById(R.id.txtView);
txt.setText(this.data.get(position).getAlamat());
view.setTag(this.data.get(position).getKonteks());
return view;
}}
我read_task.xml
<ListView
android:id="@+id/android:list"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</ListView>
而且我txt_view.xml
<TextView
android:id="@+id/txtView"
android:textSize="16sp"
android:textStyle="bold"
android:textColor="@android:color/black"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
感謝您的幫助......
嘗試使用'@android:ID/list'代替'@ + ID /安卓list' – 2013-04-08 10:21:00