LoadSir
LoadSir copied to clipboard
onReloadEvent 事件重写 点击特定view的事件 第一次无响应 ,第二次才触发 点击事件
/** * @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都出不来 点击第二次才触发点击事件
一样
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);//去重试 }); }
解决方案 在这里使用点击事件 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(); } }); } });