The last element in the row BrowseFragment

醉酒当歌 提交于 2019-12-11 05:43:57

问题


I have a Fragment:

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

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

I installed OnItemViewSelectedListener listener:

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

    setOnItemViewSelectedListener(new ItemViewSelectedListener());

override method 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?


回答1:


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.

Something like:

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
}


来源:https://stackoverflow.com/questions/37785169/the-last-element-in-the-row-browsefragment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!