在我的Android TV的應用,在ActionsRow動作按鈕失去專注於焦點迷路上adapter.notifyArrayItemRangeChanged
adapter.notifyArrayItemRangeChanged(0, 1);
電話。我使用:
View focusedView = getActivity().getCurrentFocus();
得到細緻地查看,但不能設置焦點回到notifyArrayItemRangeChanged後。與前焦點的按鈕notifyArrayItemRangeChanged失去焦點,我不能讓這個按鈕requestFocus的(或之後)onBindViewHolder的ActionPresenter的或onBindRowViewHolder ActionsRowPresenter的 ...焦點每次後設置爲第一個按鈕notifyArrayItemRangeChanged。
任何想法如何保持焦點或如何將其設置回原始視圖?
ActionPresenter:
@Override
public void onBindViewHolder(Presenter.ViewHolder viewHolder, Object item) {
Log.i(TAG, "onBindViewHolder called, item:" + item.toString());
Action action = (Action) item;
ActionViewHolder vh = (ActionViewHolder) viewHolder;
vh.mAction = action;
vh.mButton.setText(action.getLabel1());
vh.mButton.setTag(action.getId());
vh.mButton.requestFocus();
}
ActionsRowPresenter:
protected void onBindRowViewHolder(ActionsRowPresenter.ViewHolder holder, Object item) {
super.onBindRowViewHolder(holder, item);
Log.i(TAG, "onBindRowViewHolder called");
ViewHolder vh = holder;
ActionsRow row = (ActionsRow) vh.getRow();
ArrayObjectAdapter aoa = new ArrayObjectAdapter(mActionPresenter);
aoa.addAll(0, (Collection)row.getActions());
vh.bind(aoa);
}
和NowPlayingChannelRowPresenter:
public NowPlayingChannelRowPresenter(Channel c) {
setHeaderPresenter(null);
setSelectEffectEnabled(false);
mSelectedChannel = c;
npcdrPresenter = new NowPlayingChannelDetailsRowPresenter(new DetailsDescriptionPresenter());
actionsRowPresenter = new ActionsRowPresenter();
ClassPresenterSelector ps = new ClassPresenterSelector();
ps.addClassPresenter(NowPlayingChannelDetailsRow.class, npcdrPresenter);
ps.addClassPresenter(ActionsRow.class, actionsRowPresenter);
npcdRow = new NowPlayingChannelDetailsRow(mSelectedChannel);
actionsRow = new ActionsRow(mSelectedChannel);
actionsRow.addAction(new Action(ACTION_START_STOP, "Stop"));
actionsRow.addAction(new Action(ACTION_ADD_REMOVE_FAVORITE, "Add to Favorites"));
}
@Override
protected RowPresenter.ViewHolder createRowViewHolder(ViewGroup parent) {
View v = LayoutInflater.from(parent.getContext())
.inflate(R.layout.now_playing_channel_row, parent, false);
ViewHolder vh = new ViewHolder(v);
vh.mNpcdVh = (NowPlayingChannelDetailsRowPresenter.ViewHolder) npcdrPresenter.onCreateViewHolder(vh.llNpcd);
vh.llNpcd.addView(vh.mNpcdVh.view);
vh.mActionsVh = (ActionsRowPresenter.ViewHolder) actionsRowPresenter.onCreateViewHolder(vh.llActions);
vh.llActions.addView(vh.mActionsVh.view);
return vh;
}
@Override
protected void onBindRowViewHolder(RowPresenter.ViewHolder holder, Object item) {
super.onBindRowViewHolder(holder, item);
ViewHolder vh = (ViewHolder) holder;
npcdrPresenter.onBindRowViewHolder(vh.mNpcdVh, npcdRow);
actionsRowPresenter.onBindRowViewHolder(vh.mActionsVh, actionsRow);
}
編輯1:有沒有ListView中,我使用的是ArrayObjectAdapter實例與定製主持人
編輯2:我重視的佈局視圖(Hiearchy查看)。
你正在使用什麼視圖... – Lokesh 2015-03-18 08:26:58