2012-12-09 19 views
1

我跟着一些其他的問題,並拼湊一起得到這個:啓動活動不會再掀 - Android的發展

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) { 

      } 

     }); 

    } 
} 

而且也有類似的兩個活動,但與他們指向剩下的兩項活動。 所以基本上這樣:

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) { 

     } 

    }); 

每次活動兩次。他們在清單中被提及,並且xmls是正確的。它真的很奇怪,雖然它打開了最後一個選項,但劑量打開其他。而當在一開始,它不會打開任何...

我在哪裏出錯了?我也開放給任何更簡單的方法。 :) 提前致謝。我已經圍繞改變了它在所有3個活動,現在似乎打開無論我選擇相同的活動

OK:

編輯。下面的代碼:

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。

回答

0

下面是你想要的代碼,儘管可能只有一個太多或太少的括號。基本上只有一名在場的選民會被稱爲。所以把它們放在一個。

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 /位置編號和開關和案例清理您的代碼,如果你喜歡這個。

+0

感謝香港專業教育學院改變了它添加所有活動類的名字,但現在它保持起始,由相同活動每次(我發佈了上面的代碼)和乾淨的代碼,我該怎麼做? – Timmo

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> 

+0

感謝我改變了它,現在我得到另一個問題,我把上面的清單,sdk爲我添加它們,我稍微編輯它們。我編輯的問題,如果你知道如何幫助身份證真的很感激它:) – Timmo