当我在android编程中单击按钮时如何清除文本视图

时间:2013-09-13 11:31:50

标签: android textview

当我点击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);
        }
    });
}

1 个答案:

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

            }