简体   繁体   English

使用textview文本的按钮

[英]Button using text of textview

I have the following problem: 我有以下问题:

I want to use the text of a TextView which is changing every 10 seconds. 我想使用每10秒更改一次的TextView的文本。 With a Button , I want to use the text of the TextView and show it in another TextView . 使用Button ,我想使用TextView的文本并将其显示在另一个TextView

I tried it with the following code. 我尝试了以下代码。

buttonSave.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v) {

        buttonSave.setClickable(false);
        buttonSave.setVisibility(View.GONE);
        if(buttonSave.isEnabled()) {
            String copy = textView.getText().toString();
            settingsview.append("\n" + copy);
        }

        buttonSave.setEnabled(false);
}

My problem now is that it works fine until the TextView refreshes and then the TextView is clearing everything without pressing the button. 我的问题是,在刷新TextView之前, TextView可以正常工作,然后TextView无需按按钮即可清除所有内容。 This is the code which changes my textfild. 这是更改我的textfild的代码。 The toCheck StringBuilder is a input of OCR which is refreshing every 10secs toCheck StringBuilder是OCR的输入,它每10秒刷新一次

public void filterit(StringBuilder toCheck){
   Pattern patternDate = Pattern.compile("\\d{2}\\.\\d{2}\\.\\d{4}");
   Matcher matcher = patternDate.matcher(toCheck.toString());
    while (matcher.find()) {

        //textView.setText(matcher.group());
        settingsview.setText(matcher.group());
    }

}

try this way 尝试这种方式

buttonSave.setOnClickListener(new View.OnClickListener(){
    @Override
    public void onClick(View v){


        if(buttonSave.isEnabled()) {
            String copy = textView.getText().toString();
            ettingsview.setText(settingsview.getText().toString()+"\n" + copy);
            buttonSave.setClickable(false);
            buttonSave.setVisibility(View.GONE);
        }

    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM