1

I've followed some other questions and pieced it together to get this:

    public class FbFPS extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fbhtf);

        ArrayAdapter<CharSequence> adapter = ArrayAdapter
                .createFromResource(this, R.array.spagesarray,
                        android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        Spinner s = (Spinner) findViewById(R.id.spages);

        s.setAdapter(adapter);

        s.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // Display Selected option
                if (parent.getItemAtPosition(pos).toString()
                        .equals("Under 16s Reccommended Settings")) {
                    Intent i = new Intent(getApplicationContext(),
                            FbU16RS.class);
                    startActivity(i);
                    finish();
                }

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }

        });

        s.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                // Display Selected option
                if (parent.getItemAtPosition(pos).toString()
                        .equals("Recommended Privacy Settings")) {
                    Intent i = new Intent(getApplicationContext(), FbRS.class);
                    startActivity(i);
                    finish();
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }

        });

    }
}

さらに 2 つの同様のアクティビティがありますが、それらは残りの 2 つのアクティビティを指しています。だから基本的にこれ:

s.setOnItemSelectedListener(new OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int pos, long id) {
            // Display Selected option
            if (parent.getItemAtPosition(pos).toString()
                    .equals("Recommended Privacy Settings")) {
                Intent i = new Intent(getApplicationContext(), FbRS.class);
                startActivity(i);
                finish();
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {

        }

    });

すべてのアクティビティで 2 回。それらはマニフェストに記載されており、xml は正しいです。最後のオプションを開きますが、他のオプションを開きませんが、それは本当に奇妙です。そして、起動したときに、何も開かない...

どこが間違っているのですか?私はまた、より簡単な方法を受け入れます。:) 前もって感謝します。

編集:

OK、3つのアクティビティすべてで変更しましたが、選択したもので同じアクティビティを開くようになりました。コードは次のとおりです。

    public class FbRS extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fbhtf);

        final Intent iFbHTF = new Intent(FbRS.this, FbHTF.class);
        final Intent iFbU16RS = new Intent(FbRS.this, FbU16RS.class);

        ArrayAdapter<CharSequence> adapter = ArrayAdapter
                .createFromResource(this, R.array.spagesarray,
                        android.R.layout.simple_spinner_item);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        Spinner s = (Spinner) findViewById(R.id.spages);

        s.setAdapter(adapter);

        s.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view,
                    int pos, long id) {
                if (parent.getItemAtPosition(pos).toString()
                        .equals("Finding Privacy Settings")) {
                    startActivity(iFbHTF);
                    finish();
                } else if (parent.getItemAtPosition(pos).toString()
                        .equals("Under 16s Recommended Privacy Settings")) {
                    startActivity(iFbU16RS);
                    finish();
                }

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {

            }

        });

    }
}

また、マニフェストは次のとおりです。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.timmo.isp"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.timmo.isp.Home"
            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="com.timmo.isp.FbHTF"
            android:label="@string/titleFbHTF"
            android:parentActivityName="com.timmo.isp.Home" >
        </activity>
        <activity
            android:name="com.timmo.isp.FbU16RS"
            android:label="@string/titleFbU16RS"
            android:parentActivityName="com.timmo.isp.Home" >
        </activity>
        <activity
            android:name="com.timmo.isp.FbRS"
            android:label="@string/titleFbRS"
            android:parentActivityName="com.timmo.isp.Home" >
        </activity>
        <activity
            android:name="com.timmo.isp.FYMNK"
            android:label="@string/titlefymnk"
            android:parentActivityName="com.timmo.isp.Home" >
        </activity>
    </application>

</manifest>

AndroidPenguin と kongkea の助けに感謝します。

4

2 に答える 2

0

以下は必要なコードですが、ブラケットが 1 つだけ多すぎたり少なすぎたりする可能性があります。基本的に、onitemselectedlistener は 1 つだけ呼び出されます。だから、両方を1つに入れます。

public class FbFPS extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.fbhtf);

ArrayAdapter<CharSequence> adapter = ArrayAdapter
        .createFromResource(this, R.array.spagesarray,
                android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

Spinner s = (Spinner) findViewById(R.id.spages);

s.setAdapter(adapter);

s.setOnItemSelectedListener(new OnItemSelectedListener() {

    @Override
    public void onItemSelected(AdapterView<?> parent, View view,
            int pos, long id) {
        // Display Selected option
        if (parent.getItemAtPosition(pos).toString()
                .equals("Under 16s Reccommended Settings")) {
            Intent i = new Intent(getApplicationContext(),
                    FbU16RS.class);
            startActivity(i);
            finish();
        } else if (parent.getItemAtPosition(pos).toString()
                .equals("Recommended Privacy Settings")) {
            Intent i = new Intent(getApplicationContext(), FbRS.class);
            startActivity(i);
            finish();
        }

    }

    @Override
    public void onNothingSelected(AdapterView<?> arg0) {

    }

});

}
}

必要に応じて、ID/位置番号とスイッチとケースを使用してコードをクリーンアップすることもできます。

于 2012-12-09T02:45:31.910 に答える
0

FBFPS アクティビティ

Intent i = new Intent(FBFPS.this, FbU16RS.class);

上記の onClickListener で。FBFPSアクティビティのようにします。アクティビティの現在の名前を設定します Intent i = new Intent(your current activity name.this, FbRS.class);

マニフェストで、アプリケーション タグにすべてのアクティビティ クラス名を追加します。

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".ToDoListActivity" // Main activity
        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=".your activity name">
    </activity>
    <activity 
        android:name=".your activity name>
    </activity>

</application>

于 2012-12-09T02:48:51.960 に答える