안드로이드

 

 

 

 

 

class MainActivity

package kr.co.dothome.braverokmc.tutorial6;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

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

        final EditText nameText =(EditText)findViewById(R.id.nameText);
        Button button=(Button)findViewById(R.id.button);




        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String name =nameText.getText().toString();

                Intent intent =new Intent(MainActivity.this, SubActivity.class);
                intent.putExtra("name", name);
                startActivity(intent);

            }
        });

    }



}

 

 

R.layout.activity_main

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_light"
    tools:context="kr.co.dothome.braverokmc.tutorial6.MainActivity">

    <Button
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:layout_marginTop="80dp"
        android:text="@string/button"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintHorizontal_bias="0.542"
        app:layout_constraintTop_toBottomOf="@+id/nameText" />

    <EditText
        android:id="@+id/nameText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="8dp"
        android:layout_marginRight="8dp"
        android:ems="10"
        android:inputType="textPersonName"
        app:layout_constraintHorizontal_bias="0.574"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginTop="8dp" />
</android.support.constraint.ConstraintLayout>

 

 

 

class SubActivity

package kr.co.dothome.braverokmc.tutorial6;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

/**
 * Created by choi on 2017-04-25.
 */

public class SubActivity extends AppCompatActivity {


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

        TextView textView =(TextView)findViewById(R.id.nameText);

        Intent intent =getIntent();
        String name =intent.getStringExtra("name");

        textView.setText(name);

    }



}

 

 

 

R.layout.activity_sub

<?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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/nameText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/textview"
        android:textAppearance="@style/TextAppearance.AppCompat.Display1"


         />


</LinearLayout>

 

 

 

 

 

android

 

about author

PHRASE

Level 60  머나먼나라

적이 강을 건너가고 있을 때에는 반쯤 건넜을 때 공격해야 한다. -오자

댓글 ( 4)

댓글 남기기

작성