ボタンやビューを非表示

32行目が表示
35行目が非表示
[java title=”MainActivity.java” highlight=”32,35″]
package com.example.main;

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

public class MainActivty extends Activity {

//変数
Button button1,button2;
TextView text1;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);

button1 = (Button)this.findViewById(R.id.button1);
button2 = (Button)this.findViewById(R.id.button2);
text1 = (TextView)this.findViewById(R.id.text1);

button1.setOnClickListener(this);
button2.setOnClickListener(this);
}

@Override
public void onClick(View v) {
if(v==button1){
//text1を表示
text1.setVisibility(View.VISIBLE);
}else if(v==button2){
//text1を非表示
text1.setVisibility(View.INVISIBLE);
}
}
}
[/java]

Comments are closed.