行BrowseFragment中的最后一个元素

行BrowseFragment中的最后一个元素

本文介绍了行BrowseFragment中的最后一个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段:

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

BrowseFragment 中,我添加了几行内容:

In BrowseFragment I add several rows with items:

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) {
    }

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

I need to detect when the last item in the row is selected. How do I determine it?

推荐答案

您可以从递回的Row rowObject itemArrayObjectAdapter中的Row rowObject itemArrayObjectAdapter中获取所需的所有信息.在onItemSelected(...)事件中.

You can get all the information you need out of the Row row, Object item, and the ArrayObjectAdapter on the Row that are handed back in the onItemSelected(...) event.

类似的东西:

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
}

这篇关于行BrowseFragment中的最后一个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 02:41