在活动中是否有任何微不足道的情况,使得 `OnclickListener` 不起作用?

huangapple go评论64阅读模式
英文:

Is there any trivial case when `OnclickListener doesn't` work on a activity?

问题

我实现了接口 View.OnClickListener 并且覆盖了方法 onClick
问题是,所有其他的按钮和视图都能响应点击,但是一个特定的按钮却无法工作。

该按钮的 Java 代码如下:

if(v.getId() == R.id.btnResetPass){
    Log.i("test", "In ResetButton");
    resetPassword();
}

而这个按钮在 xml 文件中的代码如下:

<Button
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/btnResetPass"
    android:text="Reset"/>

当我点击这个按钮时没有任何反应。但是在 onClick 方法中,所有其他的视图和按钮都能正常工作,只有这个按钮不能。为什么它不起作用呢?

英文:

I implemented the interface View.OnclickListener and Override the method onClick.
Problem is, all other buttons and view response on click, but a particular button doesn't work.

Java code for that button is:

if(v.getId() == R.id.btnResetPass){
        Log.i(&quot;test&quot;, &quot;In ResetButton&quot;);
        resetPassword();
    }

and xml file code for this button is:

&lt;Button
    android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:id=&quot;@+id/btnResetPass&quot;
    android:text=&quot;Reset&quot;/&gt;

Nothing happens when I click on this button. But all other Views and Buttons in this onClick method
work properly accept this one. Why isn't it working then?

答案1

得分: 1

你设置了监听器吗?

button.setOnClickListener(this);
英文:

Have you set the Listener

button.setOnClickListener(this);

huangapple
  • 本文由 发表于 2020年9月24日 21:05:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/64047112.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定