如果id匹配或文件名匹配,搜索并单击按钮

问题描述 投票:2回答:1

基本概念是我将有多个按钮,例如Button AButton BButton C等。我还在屏幕顶部有一个EditText字段。

我想要做的是如果按钮名称或id与我在EditText字段中输入的内容相匹配,那么它应该自动单击该按钮。

我会为此提供java文件,但它是非常基本的,目前没有任何内容写入。

任何人都可以帮助我使用我需要在主java文件中编写的代码来匹配和链接按钮名称或id`s

android listview android-intent android-edittext
1个回答
1
投票

您必须使用TextWatcher来获取和比较文本与按钮名称。

yourEditText.addTextChangedListener(passwordWatcher);


 private final TextWatcher passwordWatcher = new TextWatcher() {
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {

    }

    public void afterTextChanged(Editable s) {
        if(yourEditText.getText().toString().equals("button1"))     {

           button1.performClick();
      }
    }
};
© www.soinside.com 2019 - 2024. All rights reserved.