0

这是我的主要 java 文件 MainActivity.java

package com.myprojects.schecklist;
import android.app.ListActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class MainActivity extends ListActivity {

    private ListView listView;
    private String[] items = { "Activity1", "Activity2" };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        listView = (ListView) findViewById(R.id.mylist);
        listView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, items));

    }
}

这里是activity_main.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/mylist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</LinearLayout>

AndroidManifest.xml

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.myprojects.schecklist"
    android:versionCode="1"
    android:versionName="1.0" >

   <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="15" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

至少我尝试了 4-5 种方法来解决这个问题。最后我尝试了Project>Clear并且它也没有修复。我尝试了一切,至少我正在处理它大约 3 天。怎么了?我要疯了。

4

2 回答 2

0

而不是扩展ListActivity尝试扩展Activity或更改您的

<ListView
        android:id="@+id/mylist"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

 <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
于 2012-07-16T10:34:59.703 回答
0

改变:

new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, items)

和:

 new ArrayAdapter<String>(this,
    android.R.layout.simple_list_item_1, android.R.id.text1, items)
于 2012-07-16T10:32:07.563 回答