gpt4 book ai didi

android - 焦点迷失在 adapter.notifyArrayItemRangeChanged 上

转载 作者:行者123 更新时间:2023-11-29 01:34:45 25 4
gpt4 key购买 nike

在我的 Android TV 应用中,ActionsRow 中的操作按钮失去了焦点

adapter.notifyArrayItemRangeChanged(0, 1);

打电话。我正在使用:

View focusedView = getActivity().getCurrentFocus();

获取焦点 View ,但不能在 notifyArrayItemRangeChanged 后重新设置焦点。 notifyArrayItemRangeChanged 之前具有焦点的按钮失去焦点,我无法在 onBindViewHolder 中(或之后)使该按钮 requestFocus>ActionPresenter 或在 ActionsRowPresenteronBindRowViewHolder 中...每次 notifyArrayItemRangeChanged 后焦点都设置到第一个按钮。 p>

关于如何保持焦点或如何将其设置回原始 View 有什么想法吗?

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: 我附加了布局 View (层次 View )。

enter image description here

最佳答案

如果您的 listview 扩展了 Activity 则尝试:

listviewName.setSelection(positionOfItem);

如果你的 listview 扩展了 ListActivity 那么试试:

getListView().setSelection(positionOfItem);

即使更新了listView,它也会聚焦在特定的位置。

关于android - 焦点迷失在 adapter.notifyArrayItemRangeChanged 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29033543/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com