Last active
July 11, 2016 20:51
-
-
Save akexorcist/0b8492341edf25c26c7f14eeb3298ad5 to your computer and use it in GitHub Desktop.
ตัวอย่างโค้ดสำหรับการเปลี่ยนหน้า Activity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:gravity="center" | |
| android:orientation="vertical" | |
| tools:context="com.akexorcist.myapplication.DoSomethingActivity"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Do Something Activity" | |
| android:textSize="20sp" /> | |
| <Button | |
| android:id="@+id/btn_back" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="30dp" | |
| android:text="Back" /> | |
| </LinearLayout> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?xml version="1.0" encoding="utf-8"?> | |
| <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:gravity="center" | |
| android:orientation="vertical" | |
| android:paddingBottom="@dimen/activity_vertical_margin" | |
| android:paddingLeft="@dimen/activity_horizontal_margin" | |
| android:paddingRight="@dimen/activity_horizontal_margin" | |
| android:paddingTop="@dimen/activity_vertical_margin" | |
| tools:context="com.akexorcist.myapplication.MainActivity"> | |
| <TextView | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Main Activity" | |
| android:textSize="20sp" /> | |
| <LinearLayout | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:layout_marginTop="30dp" | |
| android:orientation="horizontal"> | |
| <Button | |
| android:id="@+id/btn_next" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Next" /> | |
| <Button | |
| android:id="@+id/btn_close" | |
| android:layout_width="wrap_content" | |
| android:layout_height="wrap_content" | |
| android:text="Close" /> | |
| </LinearLayout> | |
| </LinearLayout> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.os.Bundle; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.view.View; | |
| import android.widget.Button; | |
| public class DoSomethingActivity extends AppCompatActivity implements View.OnClickListener { | |
| private Button btnBack; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_do_something); | |
| btnBack = (Button) findViewById(R.id.btn_back); | |
| btnBack.setOnClickListener(this); | |
| } | |
| @Override | |
| public void onClick(View view) { | |
| if (view == btnBack) { | |
| backToPrevActivity(); | |
| } | |
| } | |
| private void backToPrevActivity() { | |
| finish(); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.content.Intent; | |
| import android.os.Bundle; | |
| import android.support.v7.app.AppCompatActivity; | |
| import android.view.View; | |
| import android.widget.Button; | |
| public class MainActivity extends AppCompatActivity implements View.OnClickListener { | |
| private Button btnNext; | |
| private Button btnClose; | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_main); | |
| btnNext = (Button) findViewById(R.id.btn_next); | |
| btnClose = (Button) findViewById(R.id.btn_close); | |
| btnNext.setOnClickListener(this); | |
| btnClose.setOnClickListener(this); | |
| } | |
| @Override | |
| public void onClick(View view) { | |
| // When Click Button Next | |
| if (view == btnNext) { | |
| nextActivity(); | |
| } else if (view == btnClose) { | |
| closeThisActivity(); | |
| } | |
| } | |
| private void nextActivity() { | |
| Intent intent = new Intent(this, DoSomethingActivity.class); | |
| startActivity(intent); | |
| } | |
| private void closeThisActivity() { | |
| finish(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment