0

このクラスに問題があります。このアクティビティは、ボタンを押すと呼び出されます。Activityをこのクラスに拡張すると、プログラムはクラスに入りますが、ListActiviyを拡張してボタンをクリックすると、デバッガーは赤い単語で「ソースが見つかりません」と表示します。このアクティビティのxmlファイルまたはマニフェストに不足しているものがあるかどうかを教えてください。

これはクラスの活動です:

public class SeeAllEntriesActivity extends ListActivity {

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

        ActivitiesObjects ao = (ActivitiesObjects)this.getApplication();
        List<Customer> listOfCostumer = ao.getListOfCustomers();

        ListAdapter listAdapter = new ArrayAdapter(this, R.layout.activity_all_entries, listOfCostumer);
        ListView listViewCustomer = (ListView) findViewById(R.id.listViewCustomer);
        listViewCustomer.setAdapter(listAdapter);
    }
}

これはアクティビティのxmlです:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="all entries" />


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

    </ListView>

</LinearLayout>

これはマニフェストのxmlです:

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

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

    <application android:name="com.example.testapp.ActivitiesObjects" android:label="@string/app_name">
        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>
        <activity android:name="CreateActivity"></activity>
        <activity android:name="SeeAllEntriesActivity"></activity>
    </application>    

</manifest>

よろしくお願いします、アレックス

4

2 に答える 2

2

ListActivityに関して私が共有したい1つのポイント。

レイアウトには、android:id属性が@ android:id/listに設定されたListViewが含まれている必要があります

例:android:id = "@ android:id / list"

レイアウトファイルは以下のようになります

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="all entries" />


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

    </ListView>

</LinearLayout>

リストアダプタの設定には、setListAdapter機能を使用できます

public class SeeAllEntriesActivity extends ListActivity {

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

        ActivitiesObjects ao = (ActivitiesObjects)this.getApplication();
        List<Customer> listOfCostumer = ao.getListOfCustomers();

        ListAdapter listAdapter = new ArrayAdapter(this, R.layout.activity_all_entries, listOfCostumer);
        // no need to fetch list view instance
        // ListView listViewCustomer = (ListView) findViewById(R.id.listViewCustomer);
        setListAdapter(listAdapter);
    }
}

リストビューのインスタンスが必要な場合は、getListView ()

于 2012-08-28T14:14:05.683 に答える
1

2 " "(ドット)を忘れました。

交換:

<activity android:name="CreateActivity"></activity>
<activity android:name="SeeAllEntriesActivity"></activity>

と:

<activity android:name=".CreateActivity"></activity>
<activity android:name=".SeeAllEntriesActivity"></activity>

また、タグに2が含まれていandroid:labelます。application

于 2012-08-28T13:55:39.593 に答える