EditText
MainActivity.java
package com.example.sasakiakira.uisample2;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
/** Button. */
private Button mButton01;
/** TextView. */
private TextView mTextView01;
/** EditText. */
private EditText mEditText01;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mButton01 = (Button) findViewById(R.id.button01);
mButton01.setOnClickListener(this);
mTextView01 = (TextView) findViewById(R.id.textView01);
mEditText01 = (EditText) findViewById(R.id.editText01);
}
@Override
public void onClick(View v) {
if (v.equals(mButton01)) {
mTextView01.setText(mEditText01.getText());
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView
android:id="@+id/textView01"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TEST"
android:textSize="50px"
android:textColor="#ffffff"
android:background="#000000" />
<EditText
android:id="@+id/editText01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
android:background="#D3D3D3"
android:textSize="50px"
android:layout_below="@+id/textView01"
/>
<Button
android:id="@+id/button01"
android:text="buttonSample1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/button_anim"
android:layout_below="@+id/editText01"
>
</Button>
</RelativeLayout>