class extends ListActivity “其 id 属性为“android.R.id.list””
我试图将我的主 Activity 扩展到“ListActivity”(以前扩展到:Activity)以使用 onListItemClick,但是 logcat 向我发送“您的内容必须有一个 id 属性为 'android.r.id.list' 的 ListView ’”。 (我使用 SQLite 来填充 ListView)。
mi xml 是:
<ListView
android:id="@+id/list" // to "@id/android:list" or other styles (but nothing works)
android:layout_width="fill_parent"
android:layout_height="fill_parent"/> // or closing with </ListView>
这是 ListView 的完整 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="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent" /></LinearLayout>
我处理 ListView 的主类:
public class lay_main extends ListActivity{
public ListView list;
private DBHelper myAdap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_main);
collectXML();
setupDataBase();
setupAdapter();
}
private void collectXML()
{
list = (ListView)findViewById(R.id.list);
}
private void setupDataBase() {
myAdap = new DBHelper(getApplicationContext(), "courses", null, 1);
myAdap.insertCourses();
}
private void setupAdapter()
{
if(myAdap.getCourses()!=null)
{
cAdapter adapter = new cAdapter(this, R.layout.list_courses, myAdap.getCourses());
list.setAdapter(adapter);
}
}}
我读了 Android:您的内容必须有一个 id 属性为 android.R.id.list 的 ListView,或:RuntimeException:您的内容必须具有 id 属性为的 ListView 'android.R.id.list',以及其他问题,但对我不起作用,这是怎么回事?
非常感谢你的帮助
I'm trying to extend my main Activity to "ListActivity" (previously extends to: Activity) to use onListItemClick, but the logcat, send me "Your content must-have a ListView whose id attribute is 'android.r.id.list'". (i'm using SQLite for populate the ListView).
mi xml is:
<ListView
android:id="@+id/list" // to "@id/android:list" or other styles (but nothing works)
android:layout_width="fill_parent"
android:layout_height="fill_parent"/> // or closing with </ListView>
this is the complete xml for the ListView:
<?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="fill_parent"
android:layout_height="fill_parent" /></LinearLayout>
My main class to handle the ListView:
public class lay_main extends ListActivity{
public ListView list;
private DBHelper myAdap;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.lay_main);
collectXML();
setupDataBase();
setupAdapter();
}
private void collectXML()
{
list = (ListView)findViewById(R.id.list);
}
private void setupDataBase() {
myAdap = new DBHelper(getApplicationContext(), "courses", null, 1);
myAdap.insertCourses();
}
private void setupAdapter()
{
if(myAdap.getCourses()!=null)
{
cAdapter adapter = new cAdapter(this, R.layout.list_courses, myAdap.getCourses());
list.setAdapter(adapter);
}
}}
I read Android: Your content must have a ListView whose id attribute is android.R.id.list, or: RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list', and other questions, but don't works for me, what's going on here?
really would appreciate your help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您想扩展
ListActivity
时,您应该使用它,您将获得
ListView
作为或
以下是详细说明:如何在Activity中使用getListView()?
When you want to extend
ListActivity
you should useand you will get your
ListView
asor
Here's the detailed explanation: How to use getListView() in Activity?