Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android编程中单击按钮时清除文本视图_Android_Textview - Fatal编程技术网

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

如何在android编程中单击按钮时清除文本视图,android,textview,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

如何在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);
        }
    });
}

设置新文本后调用
invalidate()
tv.invalidate()使用setTest(null)或setText(“”)。如果您说明尝试此操作时遇到的行为,例如预期行为是否与实际行为不同,或者应用程序是否生成错误消息,这将非常有用。
//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());
                }

            }