A sentimental robot

Activity transition/intent 본문

Android Studio

Activity transition/intent

GOD03219 2018. 1. 30. 10:39

// activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#aaaaaa"
android:orientation="vertical"
tools:context="com.example.i310_54.myapplication01.MainActivity">



<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="next PAGE"
android:onClick="f1"
/>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />



</LinearLayout>

// MainActivity.java

 

package com.example.i310_54.myapplication01;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.DataSetObserver;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

public class MainActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

}


public void f1(View view) {
    
Intent intent=new Intent(getApplicationContext(),AppleActivity.class);

EditText editText=findViewById(R.id.editText);

 

intent.putExtra("eun",editText.getText().toString());

startActivity(intent);



}
}

// activity_apple.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1"
android:background="#aaaaaa"
android:orientation="horizontal"
tools:context="com.example.i310_54.myapplication01.AppleActivity">




<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />

<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="previous"
android:onClick="f1"
/>
</LinearLayout>

 

 

// AppleActivity.java

 

package com.example.i310_54.myapplication01;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

public class AppleActivity extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_apple);

Button button=findViewById(R.id.button2);

Intent intent=intent.getIntent();

String n=intent.getStringExtra("eun");

button.setText(n);




}

public void f1(View view){
finish();
}


}

// AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.i310_54.myapplication01">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".AppleActivity"
android:label="My Application02"
android:theme="@style/AppTheme">

</activity>
</application>

</manifest>

 
 



 


 

'Android Studio' 카테고리의 다른 글

Transmission  (0) 2018.01.31
Activity  (0) 2018.01.31
ListView  (0) 2018.01.29
Spinner  (0) 2018.01.29
LinearLayout  (0) 2018.01.12