Closed surbhi-jungleworks closed 4 years ago
final CountryPicker picker = CountryPicker.newInstance("Select Country");
List<Country> countryArrayList = new ArrayList<>();
countryArrayList.add(new Country("AU", "Australia", "+61", com.ybs.countrypicker.R.drawable.flag_au));
countryArrayList.add( new Country("GB", "United Kingdom", "+44", com.ybs.countrypicker.R.drawable.flag_gb));
picker.setCountriesList(countryArrayList);``
@surbhi-jungleworks your code seems to be working perfectly for me. Can you share a sample code that I can use to debug?
You need to call "sortCountries" in the place when u are setting up the recyclerView, because you are using sort for 'countries' array not for 'searchResults' array.
@Override public void setupRecyclerView(View sheetView) {
searchResults = new ArrayList<>();
searchResults.addAll(countries);
sortCountries(searchResults); // ********* ADD THIS LINE ***************
adapter = new CountriesAdapter(sheetView.getContext(), searchResults,
new OnItemClickListener() {
@Override public void onItemClicked(Country country) {
if (onCountryPickerListener != null) {
onCountryPickerListener.onSelectCountry(country);
if (bottomSheetDialog != null) {
bottomSheetDialog.dismiss();
}
if (dialog != null) {
dialog.dismiss();
}
dialog = null;
bottomSheetDialog = null;
textColor = 0;
hintColor = 0;
backgroundColor = 0;
searchIconId = 0;
searchIcon = null;
}
}
},
textColor);
countriesRecyclerView.setHasFixedSize(true);
LinearLayoutManager layoutManager = new LinearLayoutManager(sheetView.getContext());
layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
countriesRecyclerView.setLayoutManager(layoutManager);
countriesRecyclerView.setAdapter(adapter);
}
done
Subject of the issue
Sorting on the list of countries doesn't work at all
Steps to reproduce
Simply add sort code for Name & you can see it's not working
Expected behaviour
It must be handle sort options
Written Code:
val builder: CountryPicker.Builder = CountryPicker.Builder().with(this) .listener(this).sortBy(CountryPicker.SORT_BY_NAME).canSearch(false)
countryPicker = builder.build()