gpt4 book ai didi

android - 行中的最后一个元素 BrowseFragment

转载 作者:行者123 更新时间:2023-11-29 15:05:30 24 4
gpt4 key购买 nike

我有一个 fragment :

public class FilmFragment extends BrowseFragment implements LoaderManager.LoaderCallbacks<Object>

BrowseFragment 中,我添加了几行项目:

private void loadRubricsFilms(List<Rubric> mRubrics, List<Film> mFilms) {
int j = 0;

for (Rubric mRubric : mRubrics) {
ArrayObjectAdapter listRowAdapter = new ArrayObjectAdapter(mCardPresenter);

for (Film mFilm : mFilms) {
if (mFilm.getRubric() == mRubric.getId()) {
listRowAdapter.add(mFilm);
}
}
HeaderItem header = new HeaderItem(j++, mRubric.getTitle());
mRowsAdapter.add(new ListRow(header, listRowAdapter));
}
setAdapter(mRowsAdapter);
}

我安装了 OnItemViewSelectedListener 监听器:

    private final class ItemViewSelectedListener implements OnItemViewSelectedListener {
@Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
}
}

setOnItemViewSelectedListener(new ItemViewSelectedListener());

覆盖方法onItemSelected:

    @Override
public void onItemSelected(Presenter.ViewHolder itemViewHolder, Object item,
RowPresenter.ViewHolder rowViewHolder, Row row) {
}

我需要检测何时选择了行中的最后一项。我如何确定它?

最佳答案

您可以从Row 行Object itemRow 上的ArrayObjectAdapter 中获取您需要的所有信息onItemSelected(...) 事件中返回。

类似于:

final ListRow listRow = (ListRow) row;
final ArrayObjectAdapter currentRowAdapter = listRow.getAdapter();
int selectedIndex = currentRowAdapter.indexOf(item);
if (selectedIndex != -1 && (currentRowAdapter.size() - 1) == selectedIndex ) {
// The last item was selected
}

关于android - 行中的最后一个元素 BrowseFragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37785169/

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