我已经在我的代码中设置了 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) 不起作用
发布评论