Isa*_*uru 152 android android-listview
我创建了一个像这样的xml文件:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/list" >
</ListView>
Run Code Online (Sandbox Code Playgroud)
和一项活动:
public class ExampleActivity extends ListActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainlist);
}
}
Run Code Online (Sandbox Code Playgroud)
如你所见,我还没有做任何其他事情.但是我收到了错误:
您的内容必须具有ListView,其id属性为'android.R.id.list'
即使我android:id="@+id/list"
在我的xml中有这条线.
问题是什么?
And*_*lva 338
像这样重命名ListView的id,
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Run Code Online (Sandbox Code Playgroud)
由于您使用ListActivity
的是xml文件,因此必须在提及ID时指定关键字android.
如果你需要一个自定义,ListView
而不是扩展一个ListActivity
,你必须简单地扩展一个,Activity
并且应该具有相同的id而没有关键字android.
Pra*_*mar 23
您的mainlist.xml
文件中应该有一个列表视图,ID为@android:id/list
<ListView
android:id="@android:id/list"
android:layout_height="wrap_content"
android:layout_height="fill_parent"/>
Run Code Online (Sandbox Code Playgroud)
Aam*_*han 15
<ListView android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
Run Code Online (Sandbox Code Playgroud)
这应该可以解决你的问题
确切的方法我根据上面的反馈修复了这个问题,因为我最初无法让它工作:
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/list"
>
</ListView>
Run Code Online (Sandbox Code Playgroud)
MainActivity.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addPreferencesFromResource(R.xml.preferences);
Run Code Online (Sandbox Code Playgroud)
的preferences.xml:
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >
<PreferenceCategory
android:key="upgradecategory"
android:title="Upgrade" >
<Preference
android:key="download"
android:title="Get OnCall Pager Pro"
android:summary="Touch to download the Pro Version!" />
</PreferenceCategory>
</PreferenceScreen>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
101475 次 |
最近记录: |