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

onReloadEvent 事件重写 点击特定view的事件 第一次无响应 ,第二次才触发 点击事件 #168

Open
voynich-chen opened this issue Dec 8, 2021 · 3 comments

Comments

@voynich-chen
Copy link

/**
* @param onReloadListener 拿到重试的监听
* @return r
*/
@OverRide
public Callback setCallback(Context context, OnReloadListener onReloadListener) {
this.onReloadListener = onReloadListener;
return super.setCallback(context, onReloadListener);
}

/**
 * @param context c
 * @param view    v
 * @return true or  false  返回true 则覆盖注册时的onReload,如果返回false则两者都执行,先执行onReloadEvent
 */
@Override
protected boolean onReloadEvent(Context context, View view) {
    Log.d("token-", "onReloadEvent: " + System.currentTimeMillis());
    (view.findViewById(R.id.tv_reload)).setOnClickListener(v -> {
        Log.d("token-2", "onReloadEvent: " + System.currentTimeMillis());
        onReloadListener.onReload(v);//去重试
    });
    return true;
}

第一次点击 log都出不来 点击第二次才触发点击事件

@caolinxing
Copy link

一样

@ClownMonkeys
Copy link

rootView.setOnClickListener(v -> {
if (onReloadEvent(context, rootView)) {
return;
}
if (onReloadListener != null) {
onReloadListener.onReload(v);
}
});
在第一次点击之后才注册了 按钮的点击事件
//将Callback添加到当前视图时的回调,View为当前Callback的布局View
@OverRide
public void onAttach(Context context, View view) {
super.onAttach(context, view);
(view.findViewById(R.id.tv_reload)).setOnClickListener(v -> {
Log.d("token-2", "onReloadEvent: " + System.currentTimeMillis());
onReloadListener.onReload(v);//去重试
});
}

@caolinxing
Copy link

解决方案 在这里使用点击事件
loadService.setCallBack(EmptyCallback.class, new Transport() {
@OverRide
public void order(Context context, View view) {
Button btn= (TextView) view.findViewById(R.id.btn);
btn.setOnClickListener(new View.OnClickListener() {
@OverRide
public void onClick(View v) {
Toast.makeText(context.getApplicationContext(), "It's your gift! :p", Toast.LENGTH_SHORT).show();
}
});
}
});

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

No branches or pull requests

3 participants