Merge pull request #10024 from osmandapp/HorizontalSelectionAdapterFix
Fix get item by position
This commit is contained in:
commit
ed7e379adb
3 changed files with 10 additions and 7 deletions
|
@ -632,7 +632,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment {
|
|||
iconCategoriesRecyclerView.setAdapter(horizontalSelectionAdapter);
|
||||
iconCategoriesRecyclerView.setLayoutManager(new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false));
|
||||
horizontalSelectionAdapter.notifyDataSetChanged();
|
||||
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPosition(selectedIconCategory));
|
||||
iconCategoriesRecyclerView.smoothScrollToPosition(horizontalSelectionAdapter.getItemPositionByTitle(selectedIconCategory));
|
||||
for (String name : iconNameList) {
|
||||
selectIcon.addView(createIconItemView(name, selectIcon), new FlowLayout.LayoutParams(0, 0));
|
||||
}
|
||||
|
|
|
@ -110,13 +110,16 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
|
|||
return items.size();
|
||||
}
|
||||
|
||||
public int getItemPosition(String name) {
|
||||
return items.indexOf(name);
|
||||
public int getItemPositionByTitle(String title) {
|
||||
return getItemPosition(getItemByTitle(title));
|
||||
}
|
||||
|
||||
public void setSelectedItemByTitle(String selectedItemTitle) {
|
||||
HorizontalSelectionItem selectedItem = getItemByTitle(selectedItemTitle);
|
||||
setSelectedItem(selectedItem);
|
||||
public int getItemPosition(HorizontalSelectionItem item) {
|
||||
return items.indexOf(item);
|
||||
}
|
||||
|
||||
public void setSelectedItemByTitle(String title) {
|
||||
setSelectedItem(getItemByTitle(title));
|
||||
}
|
||||
|
||||
public void setSelectedItem(HorizontalSelectionItem selectedItem) {
|
||||
|
|
|
@ -122,7 +122,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
|
|||
}
|
||||
selectedItem = preference.getEntryFromValue(String.valueOf(currentValue));
|
||||
adapter.setSelectedItemByTitle(selectedItem);
|
||||
int itemPosition = adapter.getItemPosition(selectedItem);
|
||||
int itemPosition = adapter.getItemPositionByTitle(selectedItem);
|
||||
if (itemPosition >= 0) {
|
||||
recyclerView.smoothScrollToPosition(itemPosition);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue