使用Android按钮切换到不同的Activity

相逢意气为君饮,系马高楼垂柳边。这篇文章主要讲述使用Android按钮切换到不同的Activity相关的知识,希望能为你提供帮助。
我在屏幕上有按钮,当我按下屏幕上的按钮时,我想要进行不同的活动。
应用程序正在运行,但按钮停止。
请帮我。我正在学习android。抱歉坏英语。
我的班级档案;

public void git1(View view) {this.view = view; Intent intent1 = new Intent(getApplicationContext(),first.class); startActivity(intent1); }public void git2(View view) {this.view = view; Intent intent2 = new Intent(getApplicationContext(),second.class); startActivity(intent2); }public void git3(View view) {this.view = view; Intent intent = new Intent(getApplicationContext(),third.class); startActivity(intent); }public void git4(View view) {this.view = view; Intent intent = new Intent(getApplicationContext(),fourth.class); startActivity(intent); }public void git5(View view) {this.view = view; Intent intent = new Intent(getApplicationContext(),fifth.class); startActivity(intent); }

【使用Android按钮切换到不同的Activity】That's how the design looks.
我们是CML鱼片;
< TextView android:id="@+id/textView2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Anket Se?iniz :" tools:layout_editor_absoluteX="16dp" tools:layout_editor_absoluteY="16dp" /> < Button android:id="@+id/s1button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/textView2" android:layout_marginTop="45dp" android:onClick="git1" android:text="1. Hasta Memnuniyeti Anketi " android:textAlignment="textStart" app:layout_constraintBottom_toTopOf="@+id/s2button" app:layout_constraintStart_toStartOf="@+id/s2button" /> < Button android:id="@+id/s2button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/s1button" android:layout_marginTop="34dp" android:onClick="git2" android:text="2. Di? Bak?m? Anketi " android:textAlignment="textStart" app:layout_constraintBottom_toTopOf="@+id/s3button" app:layout_constraintStart_toStartOf="@+id/s3button" /> < Button android:id="@+id/s3button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/s2button" android:layout_marginTop="25dp" android:onClick="git3" android:text="3. Türkiye Geneli Fenotip Anketi " android:textAlignment="textStart" app:layout_constraintStart_toStartOf="@+id/s4button" tools:layout_editor_absoluteY="231dp" /> < Button android:id="@+id/s4button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/s3button" android:layout_marginTop="31dp" android:onClick="git4" android:text="4. Yabani Hayvanlar Anketi" android:textAlignment="textStart" app:layout_constraintStart_toStartOf="@+id/s5button" tools:layout_editor_absoluteY="307dp" /> < Button android:id="@+id/s5button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/s4button" android:layout_marginTop="37dp" android:onClick="git5" android:text="5. üRüN MEMNUN?YET ANKET?" android:textAlignment="textStart" app:layout_constraintTop_toBottomOf="@+id/s4button" tools:layout_editor_absoluteX="31dp" />

答案例如:
@Override public void onCreate(Bundle savedInstanceState) { Button b1 = (Button) findViewById(R.id.buttonplay); b1.setOnClickListener(this); //{YOUR APP} }@Override public void onClick(View v) { // Perform action on click switch(v.getId()) { case R.id.buttonplay: //Play voicefile MediaPlayer.create(getBaseContext(), R.raw.voicefile).start(); break; case R.id.buttonstop: //Stop MediaPlayer MediaPlayer.create(getBaseContext(), R.raw.voicefile).stop(); break; }}}

我希望我能帮到你

    推荐阅读