我有一个ViewHolder,并在bindView()方法中设置了一个 OnLongClickListener 。
当我旋转设备并长按列表项 java.lang.IllegalStateException:在发生onSaveInstanceState 异常后无法执行此操作。
我已经重写了show()方法并测试了 commitAllowingStateLoss ,但仍然出现异常。
有人可以帮助我吗?
public void bindView(final FragmentActivity activity) {
...
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
FingerprintDialogFragment fingerprintDialogFragment = FingerprintDialogFragment.getInstance(DecreeItemViewHolder.this);
fingerprintDialogFragment.show(activity.getSupportFragmentManager(), FINGERPRINT_DIALOG_TAG);
return true;
});
}
}
答案 0 :(得分:0)
我通过委派解决了问题...
在呼叫者类中添加 checkFingerprintAuthentication()方法:
void checkFingerprintAuthentication() {
FingerprintDialogFragment fingerprintDialogFragment = FingerprintDialogFragment.getInstance(this);
fingerprintDialogFragment.show(getActivity().getSupportFragmentManager(), FINGERPRINT_DIALOG_TAG);
}
将呼叫者类作为参数发送给查看持有者,并调用 checkFingerprintAuthentication():
public void bindView(final DecreeCartableController cartableController) {
...
itemView.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
cartableController.checkFingerprintAuthentication();
return true;
}
});
}
问题解决了! :)