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

标签 android listview android-intent android-edittext

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

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

我会为此提供 java 文件,但它非常基础,目前没有在其中写入任何内容。

谁能帮我写我需要在主 java 文件中匹配和链接按钮名称或 ID 的代码

最佳答案

您必须使用 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();
      }
    }
};

关于android - 如果 ID 匹配或文件名匹配,搜索并单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37246322/

相关文章:

Android 解绑服务

java - BOOT_COMPLETED 并且已经从 AlarmManager 执行了警报

android - 通过 Android 应用程序在 USB 端口上发送和接收数据

Android 通知未显示

android - 清除android中的所有 Activity

java - 为什么我的弹出窗口与 ListView 发生冲突?

android - 为什么 Android Studio Lint 在使用 TypedArray 时会发出警告?

android - 将不同的图像添加到我的适配器并在 ListView 中显示它们

java - 让 fragment 知道某个 ListView 项目何时出现在屏幕上

android - Android 中什么决定了应用程序在启动时自动启动?