Button.setClickable(false) 不起作用

编程入门 行业动态 更新时间:2024-10-14 20:18:56
本文介绍了Button.setClickable(false) 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经在我的代码中设置了 mButton.setClickable(false); 但这个按钮仍然被我的代码的全局 button.setOnClickListener 调用.

I have set mButton.setClickable(false); in my code but still this button is invoked by global button.setOnClickListener of my code.

抱歉更新延迟.以下是我遇到问题的详细信息视图.在我的 listview customAdapter 类中的 getView 方法

sorry for the delayed update. Below is the details view where I face the issue. inside my listview customAdapter class getView method

@Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; YourWrapper wrapper = null; HashMap<String, Object> cTa= new HashMap<String, Object>(); cTa= d.getPosition(position) Button mButton = (Button)convertView.findViewById(R.id.mBtn); if (row == null) { row = inflater.inflate(R.layout.layout, parent, false); wrapper = new YourWrapper (row); row.setTag(wrapper); } else wrapper = (YourWrapper) row.getTag(); if(success) { // section-1 mButton.setClickable(true); } else{ // section-2 mButton.setClickable(false); mButton.setFocusable(false); } wrapper.getButton().setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { //operation } }); return row; }

以上是当前工作的代码,在第 2 部分,它使 mButton 可点击 - 假,可聚焦 - 假,但它仍然侦听下面的 wrapper.getButton().setOnClickListener() 并执行操作.请建议我.抱歉延迟更新.谢谢!

Above is the current code which working,and on section-2 it makes the mButton clickable- false, and focusable - false but still it's listen the below wrapper.getButton().setOnClickListener() and perform the operation. Please suggest me. Sorry for delayed update. Thanks!

更新:我已经做了以下修补程序,现在可以解决这个问题.

UPDATE: I have made below hot-fixes that solve the problem for now.

// section-2 mButton.setVisibility(View.GONE); mButton.setClickable(false); mButton.setFocusable(false);

推荐答案

这似乎是设计使然.这是来自 View.setOnClickListener 方法:

That seems to be by design. This is from the documentation of the View.setOnClickListener method:

注册一个回调,当这个视图被点击时被调用.如果此视图不可点击,则它变为可点击.

Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.

更多推荐

Button.setClickable(false) 不起作用

本文发布于:2023-11-24 01:13:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1623428.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   Button   setClickable   false

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!