我已经搜索论坛的类似问题,并且据我所知我正在按照其他解决方案的方式进行,但我仍然得到错误“您的内容必须有一个列表视图,其id属性是android.r.id.list”你的内容必须有一个listview,其id属性是'android.r.id.list'
我MainActivity.java样子:
public class MainActivity extends ListActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
setListAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
new ArrayList<String>()));
}
我activity_main.xml中:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="dk.beatpro.mibfinder.MainActivity"
tools:ignore="MergeRootFrame" />
而且fragment_mail.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="dk.beatpro.mibfinder.MainActivity$PlaceholderFragment" >
<Button
android:id="@+id/button_findMIB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/button_findMIB" />
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_findMIB" />
</RelativeLayout>
但我得到以下运行时错误:
06-24 09:00:07.726: E/AndroidRuntime(10542): FATAL EXCEPTION: main
06-24 09:00:07.726: E/AndroidRuntime(10542): Process: dk.beatpro.mibfinder, PID: 10542
06-24 09:00:07.726: E/AndroidRuntime(10542): java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.beatpro.mibfinder/dk.beatpro.mibfinder.MainActivity}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
即使我有android:id="@android:id/list"
为<ListView\>
元素。
谁能告诉我我在这里失踪了什么?
非常感谢。摆脱片段做了诀窍。我会接受你的回答:) –