我正在创建一个显示数据库值的布局。但是这个错误出现在logcat:
中Your content must have a ListView whose id attribute is 'android.R.id.list'
这是我的ListActivity:
import android.app.ListActivity;
import android.database.Cursor;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.SimpleCursorAdapter;
import android.widget.SimpleCursorAdapter.ViewBinder;
import android.widget.TextView;
public class Row_User extends ListActivity
{
private static String TAG = "Row_User";
static final String[] FROM = { Data.C_USER, Data.C_PASS };
static final int[] TO = { R.id.row_user, R.id.row_pass };
Cursor cursor;
SimpleCursorAdapter adapter;
@Override
protected void onCreate(Bundle savedInstanceState)
{
Log.d(TAG, "onCreate-------Start");
super.onCreate(savedInstanceState);
setContentView(R.layout.row_users);
make_and_fill_rows();
Log.d(TAG, "onCreate-------End");
}
static final ViewBinder VIEW_BINDER = new ViewBinder()
{
public
boolean
setViewValue(
View view,
Cursor cursor,
int columnIndex)
{
Log.d(
TAG,
"Entering switch-case...");
switch (view
.getId())
{
case R.id.row_user:
((TextView) view)
.setText("userrrrrr");
return true;
case R.id.row_pass:
((TextView) view)
.setText("passssssss");
return true;
default:
return false;
}
}
};
private void make_and_fill_rows()
{
Log.d(TAG, "make_and_fill_rows-----Start");
cursor = ((Constant) getApplication()).data.query("1=1", null);
adapter =
new SimpleCursorAdapter(
this,
R.layout.row_users,
cursor,
FROM,
TO);
adapter.setViewBinder(VIEW_BINDER);
setTitle("کاربران");
setListAdapter(adapter);
Log.d(TAG, "make_and_fill_rows-----End");
}
}
这是我的布局xml:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" >
<TextView
android:id="@+id/row_user"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:text="user" />
<TextView
android:id="@+id/row_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="22dp"
android:text="pass" />
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
</LinearLayout>
我在另一个布局中有一个按钮,它在onClickListener中启动此活动。 有人可以帮我吗?
答案 0 :(得分:1)
替换此行
android:id="@+id/list"
用这个
android:id="@android:id/list"
你得到的例外
Your content must have a ListView whose id attribute is 'android.R.id.list'
它说您必须使用已存在的资源ID ListView
定义android.R.id.list
,您可以使用@android:id/list