0

当我在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);
        }
    });
}
4

1 回答 1

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

            }
于 2013-09-13T12:06:37.377 回答