0
直指點。我試圖用amlcurran顯示使用ShowcaseView庫的coachmark系列:https://github.com/amlcurran/ShowcaseViewAndroid ShowcaseView沒有顯示遞歸方法
我無法獲得coachmark顯示。問題是runCoachMark()方法總是返回null。在mMainAdapter的notifyDatasetChaned()後面運行runCoachMark()方法。我試圖使用Handler()。postDelayed()和Thread.sleep()沒有成功。
任何人都可以解釋爲什麼會發生這種問題並解決這個問題。謝謝。
private static final int COACHMARK_A = -3;
private static final int COACHMARK_B = -2;
private static final int COACHMARK_C = -1;
// ... some other coachmark type
private static final int END_COACHMARK = 0;
private static final int SCROLL_OFFSET = 56;
private static final long COACHMARK_DELAY = 200L;
private void runCoachMark(int type) {
if (type == END_COACHMARK) {
return;
}
View v = getCoachMarkView(type);
if (v == null) {
return;
}
showCoachMark(getActivity(), v, type);
}
@Nullable
private View getCoachMarkView(final int type) {
safeScrollTo(getPos(type), SCROLL_OFFSET);
return mMainList.getChildAt(0).findViewById(getCoachMarkId(type));
}
private void safeScrollTo(final int pos, final int offset) {
mMainList.setLayoutFrozen(true);
mLayoutManager.scrollToPositionWithOffset(pos, offset);
mMainList.setLayoutFrozen(false);
}
private int getCoachMarkId(int type) {
int id;
switch (type) {
case COACHMARK_A:
id = R.id.A;
break;
case COACHMARK_B:
id = R.id.B;
break;
case COACHMARK_C:
id = R.id.C;
break;
// ... some other types
default:
id = 0;
break;
return id;
}
private int getPos(int type) {
int pos;
switch (type) {
case COACHMARK_A:
pos = 1;
break;
case COACHMARK_B:
pos = 4;
break;
case COACHMARK_C:
pos = 5;
break;
// ... some other cases
default:
pos = 0;
break;
}
return pos;
}
private void showCoachMark(final Context context, final View v, final int type) {
new ShowcaseView.Builder(getActivity())
.setTarget(new ViewTarget(v.getId(), (Activity) context))
.setContentTitle(getTitle(type))
.setContentText(getDescription(type))
.setShowcaseDrawer(new CustomShowcaseView(v))
.setShowcaseEventListener(new OnShowcaseEventListener() {
@Override
public void onShowcaseViewHide(ShowcaseView showcaseView) {
}
@Override
public void onShowcaseViewDidHide(ShowcaseView showcaseView) {
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
runCoachMark(type++);
}
}, COACHMARK_DELAY);
}
@Override
public void onShowcaseViewShow(ShowcaseView showcaseView) {
}
@Override
public void onShowcaseViewTouchBlocked(MotionEvent motionEvent) {
}
})
.build();
}
}