行中的最后一个元素 BrowseFragment
The last element in the row BrowseFragment
我有一个片段:
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 row
、Object item
和 Row
上的 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
}
我有一个片段:
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 row
、Object item
和 Row
上的 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
}