0

配列内にスペースがある場合に新しいインテントを開く方法(「HelloWorld」など)アクセスしようとしているクラスはstartingPointと呼ばれます。

-> android:name = ""内にスペースを含めることができないため、エラーが発生します

回避策はありますか?

前もって感謝します

Root.java

public class Root extends ListActivity {

String classes[] = { "Hello World", "Another Item", "Email"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setListAdapter(new ArrayAdapter<String>(Root.this,
            R.layout.root, classes));
}

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    String MENU_CHOICE = classes[position];
    try {
        Class ourClass = Class.forName("se.hello.visboken." + MENU_CHOICE);
        Intent ourIntent = new Intent(Root.this, ourClass);
        startActivity(ourIntent);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}
}

私のマニフェストはこんな感じ

    <activity
        android:name=".Splash"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".Root"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="se.hello.visboken.ROOT" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
    <activity
        android:name=".startingPoint"
        android:label="Hello World" >
        <intent-filter>
            <action android:name="se.hello.visboken.startingPoint" />

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

1 に答える 1

0

あなたの場合、起動する必要のあるアクティビティはstartingPoint、ではなく Hello Worldです。HelloWorldはそのアクティビティのタイトルです。


アップデート:

同じサイズ(必須)の別の文字列配列を作成しますが、タイトルではなくクラスの名前が含まれています。

String tmp[] = { "startingPoint", "anotherClass1", "anotherClass2"};

onListItemClickで、次のように読みます。

String MENU_CHOICE = tmp[position];
于 2012-05-08T18:37:27.117 に答える