2016-05-02 14 views
0

私は、お互いがレイアウトを開く他のものを開くアクティビティを持っています。他のアクティビティの存在がないレイアウトを開くための私の最初のアクティビティですか?レイアウトを開く方法setOnClickListener

Activity1.java

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 

public class Activity1 extends Activity { 

@Override 
public void onCreate(Bundle savedInstanceState) { 

    super.onCreate(savedInstanceState); 
    setContentView(R.layout.button1); // Αναζητούμε τα στοιχεία του κουμπιού 
    Button button1 = (Button) findViewById(R.id.button1);// Πατώντας το button1 ανοίγει μία νέα δραστηριότητα 
    Button button2 = (Button) findViewById(R.id.button2); 
    Button button3 = (Button) findViewById(R.id.button3); 
    Button button4 = (Button) findViewById(R.id.button4); 
    Button button5 = (Button) findViewById(R.id.button5); 
    Button button6 = (Button) findViewById(R.id.button6); 
    Button button7 = (Button) findViewById(R.id.button7); 
    Button button8 = (Button) findViewById(R.id.button8); 
    Button button9 = (Button) findViewById(R.id.button9); 
    Button button10 = (Button) findViewById(R.id.button10); 
    Button button11 = (Button) findViewById(R.id.button11); 
    Button button12 = (Button) findViewById(R.id.button12); 
    Button button13 = (Button) findViewById(R.id.button13); 
    Button button14 = (Button) findViewById(R.id.button14); 
    Button button15 = (Button) findViewById(R.id.button15); 
    Button button16 = (Button) findViewById(R.id.button16); 
    Button button_end = (Button) findViewById(R.id.button_end); 


    button1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_1.class); 
      startActivity(intent); 
     } 
    }); 

    button2.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_2.class); 
      startActivity(intent); 
     } 
    }); 
    button3.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_3.class); 
      startActivity(intent); 
     } 
    }); 
    button4.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_4.class); 
      startActivity(intent); 
     } 
    }); 
    button5.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_5.class); 
      startActivity(intent); 
     } 
    }); 
    button6.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_6.class); 
      startActivity(intent); 
     } 
    }); 

    button7.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_7.class); 
      startActivity(intent); 
     } 
    }); 
    button8.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_8.class); 
      startActivity(intent); 
     } 
    }); 
    button9.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_9.class); 
      startActivity(intent); 
     } 
    }); 
    button10.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_10.class); 
      startActivity(intent); 
     } 
    }); 
    button11.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_11.class); 
      startActivity(intent); 
     } 
    }); 
    button12.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_12.class); 
      startActivity(intent); 
     } 
    }); 

    button13.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_13.class); 
      startActivity(intent); 
     } 
    }); 
    button14.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_14.class); 
      startActivity(intent); 
     } 
    }); 
    button15.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_15.class); 
      startActivity(intent); 
     } 
    }); 
    button16.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      Intent intent = new Intent(); 
      intent.setClass(getApplicationContext(), Activity_Photo_16.class); 
      startActivity(intent); 
     } 
    }); 
    button_end.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 
      { 
       finish(); 
      } 
     } 
    }); 
} 

}

これは、インの間に活動

Activity_Photo1.java

import android.app.Activity; 
import android.os.Bundle; 

public class Activity_Photo_1 extends Activity { 

    @Override public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.photo_1); 
    } 
} 

の一つであり、これは、レイアウトの一つである

私が正しい理解していれば

photo1.xml

<ScrollView 
    xmlns:android="http://schemas.android.com/apk/res/android" 


    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFCC0000"> 

<RelativeLayout 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="#FFCC0000"> 


    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="57dp" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="@string/button1_1" 
     android:id="@+id/textView3" 
     android:layout_gravity="center_horizontal" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="350dp" 
     android:id="@+id/imageView" 
     android:src="@drawable/photo_1" 
     android:layout_gravity="center_horizontal" 
     android:layout_below="@+id/textView3" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_marginTop="52dp" /> 
</RelativeLayout> 
</ScrollView> 
+0

あなたが他の人のactivitysの存在なしには何をすることによって意味ですか? – Exception

+0

あなたの質問は明確ではありません。 setonclicklistnerを使用せずに別のクラスを開く場合は、 –

+1

を編集してください。フラグメント –

答えて

0

は、コードのこの部分を試してみてください。

Intent intent = new Intent(getApplicationContext(), Home.class); 
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 
startActivity(intent); 
関連する問題