0

大家好,我需要一些帮助来解决我的问题。我想显示所有数据database。但是当我尝试显示时,我在日志 Cat 中出现这样的错误:您的内容必须有一个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"
    />

谢谢你的帮助...

4

2 回答 2

1

更改android:id="@+id/android:list"android:id="@android:id/list",这应该可以完成工作。

于 2013-04-08T10:21:11.393 回答
0

使用android:id="@android:id/list",您的 ListView 应通过以下方式找到:

taskList = getListView();
于 2013-04-08T10:34:32.313 回答