Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

能否在SwitchClickListener返回被点击的View #87

Closed
farsunset opened this issue May 12, 2018 · 9 comments
Closed

能否在SwitchClickListener返回被点击的View #87

farsunset opened this issue May 12, 2018 · 9 comments
Labels
Milestone

Comments

@farsunset
Copy link

能否在SwitchClickListener返回被点击的View,多个panel的情况下,需要这个View来做一些判断。还有如何在登录页面记录下来 键盘高度,这样就不需要使用min-panel-height的配置了

@Jacksgong Jacksgong added this to the 1.6.2 milestone May 12, 2018
@Jacksgong
Copy link
Owner

已经在1.6.2-SNAPSHOT上实现,你可以添加以下仓库后,引入1.6.2-SNAPSHOT版本进行验证:

allprojects {
  repositories {
      maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
  }
}

@farsunset
Copy link
Author

好的,谢谢

@r17171709
Copy link

@Jacksgong 使用快照版本这样无效 api 'cn.dreamtobe.kpswitch:library:1.6.2-SNAPSHOT'

@Jacksgong
Copy link
Owner

Jacksgong commented Oct 9, 2018

@r17171709 你要先参考上面提到的申明仓库,anyway,我已经发布了1.6.2,你可以直接使用1.6.2了。

@Harlber
Copy link

Harlber commented Oct 23, 2018

感谢官方支持该功能,之前项目中采用hook performClick来实现

@r17171709 实在不行可以试试我的方案,将需要知道被点击的view用PostClickImageView替换

@SuppressLint("AppCompatCustomView")
public class PostClickImageView extends ImageView {
   private OnPostClickListener onPostClickListener;

   public PostClickImageView(Context context) {
       super(context);
   }

   public PostClickImageView(Context context, @Nullable AttributeSet attrs) {
       super(context, attrs);
   }

   public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
       super(context, attrs, defStyleAttr);
   }

   @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
   public PostClickImageView(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) {
       super(context, attrs, defStyleAttr, defStyleRes);
   }

   @Override
   public boolean performClick() {
       boolean shouldClick = super.performClick();
       if (shouldClick && onPostClickListener != null) {
           onPostClickListener.performClick(this);
       }
       return shouldClick;
   }


   public static interface OnPostClickListener {

       void performClick(View v);
   }

   public void setOnPostClickListener(OnPostClickListener onPostClickListener) {
       this.onPostClickListener = onPostClickListener;
   }
}

@chentao7v
Copy link

chentao7v commented Oct 23, 2018

@Harlber 点击事件的回调没有修复啊,1.6.2的代码中依然是

               if (switchClickListener != null && switchToPanel != null) {
                    switchClickListener.onClickSwitch(v, switchToPanel);
                }

@Harlber
Copy link

Harlber commented Oct 26, 2018

那你可以试试上面我提及的hook performClick的方式,我项目中用的解决方案 @chentao7v

@farsunset
Copy link
Author

大佬。1.6.2这个功能是加上了,但是有个bug ,场景如下
2个Switch 分别为Switch1, Switch2
当前panel1为Switch1,这个时候点击Switch2,切换到panel2,功能没有问题,但是onClickSwitch回调没有触发,这个时候再点击一次Switch2才会触发,我希望只要是点击了Switch,就一定回调onClickSwitch,希望早日解决,谢谢;

@wangzhanxian
Copy link

可以给点击的View设置setOnTouchListener,这个是在onClick之前执行的,如果返回true,还可以屏蔽掉点击事件

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants