コンテンツにスキップ

TextView

MainActivity.java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.gclue.myapplication;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends Activity implements View.OnClickListener {

    /** Button. */
    private Button mButton01;

    /** TextView. */
    private TextView mTextView01;

    @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);
    }

    @Override
    public void onClick(View v) {
        if  (v.equals(mButton01)) {
            mTextView01.setText("Button Clicked");
        }
    }
}

activity_main.xml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?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"
    tools:context=".MainActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="TEST"
        android:textSize="50px"
        android:id="@+id/textView01"
        android:textColor="#ffffff"
        android:background="#000000"
        android:layout_centerHorizontal="true" />

    <Button
        android:id="@+id/button01"
        android:text="buttonSample1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView01"
        >
    </Button>


</RelativeLayout>