2013-07-26 23 views

回答

1

您必須創建2個單獨的活動才能在彼此之間移動。在下面我添加了2個活動類(簡單的一個)的示例代碼。您需要在AndroidManifest.xml文件中添加兩個活動。

對於按鈕點擊需要爲它添加OnClickListener類。檢查這個How to navigate from one screen to another screen

MainActivity.java

public class MainActivity extends Activity { 

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

      //To delay 3 seconds to move next screen 
      final Handler handler = new Handler(); 
      handler.postDelayed(new Runnable() { 
       public void run() { 
        moveActivity(); 
       } 
      }, 3000); 

     } 

     public void moveActivity() 
     { 
      Intent goToNextActivity = new Intent(getApplicationContext(), SecondActivity.class); 
      startActivity(goToNextActivity); 
     } 

    } 

SecondActivity.java

public class SecondActivity extends Activity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.my_second_activity); //Layout XML File 
    } 


} 

AndroidManifest.xml中

<application 
     android:allowBackup="true" 
     android:icon="@drawable/ic_launcher" 
     android:label="@string/app_name" 
     android:theme="@style/AppTheme" > 
     <activity 
      android:name="com.example.app.MainActivity" 
      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.example.app.SecondActivity" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN"/> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
    </application>