2012-12-09 20 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