2

我有一个片段:

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

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

4

1 回答 1

5

您可以从事件中返回的Row rowObject itemArrayObjectAdapter上获取所需的所有信息。RowonItemSelected(...)

就像是:

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
}
于 2016-06-13T16:46:34.823 回答