package com.purelymean.earnings;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;
public class Main extends Activity{
/**Called when activity is first created. */
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button) findViewById(R.id.button);
TextView tx = (TextView) findViewById(R.id.textView1);
}
}
我需要做什么才能在点击按钮时将textview
更改为我放的任何内容?
答案 0 :(得分:2)
您应该在按钮上添加OnClickListener
并覆盖onClick
功能,以便在TextView
Button b = (Button) findViewById(R.id.button);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TextView tx = (TextView) findViewById(R.id.textView1);
tx.setText("yourtext");
}
});
答案 1 :(得分:1)
在您的按钮上添加OnClickListener
即可。
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
tx.setText("It Works!");
}
});