当我点击android编程中的按钮时如何清除文本视图
chk1=(CheckBox)findViewById(R.id.one);
chk2=(CheckBox)findViewById(R.id.two);
chk3=(CheckBox)findViewById(R.id.three);
btn=(Button)findViewById(R.id.btn);
tv=(TextView)findViewById(R.id.tv);
btn.setOnClickListener(
new OnClickListener()
{
@Override
public void onClick(View arg0) {
tv.setText(" ");
if(chk1.isChecked()) {
str+=chk1.getText().toString();
}
if(chk2.isChecked()) {
str+=chk2.getText().toString();
}
if(chk3.isChecked()) {
str+=chk3.getText().toString();
}
tv.setText(str);
tv.setFreezesText(true);
}
});
}
答案 0 :(得分:1)
//try this
@Override
public void onClick(View arg0) {
txt.setText("");
if(chkFirst.isChecked()){
txt.setText(txt.getText().toString()+" "+chkFirst.getText().toString());
}
if(chkSecond.isChecked()){
txt.setText(txt.getText().toString()+" "+chkSecond.getText().toString());
}
if(chkThird.isChecked()){
txt.setText(txt.getText().toString()+" "+chkThird.getText().toString());
}
}