2015-03-13 43 views
2

在我的Android TV的應用,在ActionsRow動作按鈕失去專注於焦點迷路上adapter.notifyArrayItemRangeChanged

adapter.notifyArrayItemRangeChanged(0, 1); 

電話。我使用:

View focusedView = getActivity().getCurrentFocus(); 

得到細緻地查看,但不能設置焦點回到notifyArrayItemRangeChanged後。與前焦點的按鈕notifyArrayItemRangeChanged失去焦點,我不能讓這個按鈕requestFocus的(或之後)onBindViewHolder的ActionPresenteronBindRowViewHolder 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查看)。

enter image description here

+0

你正在使用什麼視圖... – Lokesh 2015-03-18 08:26:58

回答

0

這應該讓只要求需要被集中

vh.mButton.requestFocus項目();

如果通知適配器只是在ActionPresenter的第一個項目,onBindViewHolder要調用的第一個項目,它將獲得焦點。

如果是第二個需要關注的項目,ActionPresenter的onBindViewHolder應該被調用以獲取該項目,並且您只能請求關注第二個項目而不是所有項目。

+0

如何爲適用於第一個項目的適配器不提供幫助?我必須重寫ActionsRowPresenter中的方法嗎? – burakk 2015-03-23 13:28:04

+0

你想專注於第一項還是第二項? adapter.notifyArrayItemRangeChanged(0,1)中包含哪些適配器? – random 2015-03-24 03:40:03

+0

該適配器包含NowPlayingChannelRow,它由NowPlayingChannelDetailsRow和ActionsRow組成(請參閱圖像)。我只想要刷新NowPlayingChannelDetailsRow,從而調用adapter.notifyArrayItemRangeChanged(0,1);當它被調用時,ActionsRow被再次渲染,並且焦點丟失 – burakk 2015-03-25 09:01:28

1

如果您listview擴展Activity然後嘗試:

listviewName.setSelection(positionOfItem); 

,如果你listview延伸ListActivity然後嘗試:

getListView().setSelection(positionOfItem); 

它甚至會後集中在特定位置listView被更新。

+0

謝謝,但沒有listview。 – burakk 2015-03-14 11:32:00