Open DigitalChip opened 7 years ago
Solution: Need use obtainTypedArray for get TypedArray in method convertResourceArraysToIconsArrayList(...):
public static ArrayList<SelectableIcon> convertResourceArraysToIconsArrayList(Context context, boolean sortByName, @ArrayRes int idsArray, @ArrayRes int namesArray, @ArrayRes int drawablesArray) {
//get and check arrays
String[] ids = context.getResources().getStringArray(idsArray);
String[] names = context.getResources().getStringArray(namesArray);
TypedArray drawables = context.getResources().obtainTypedArray(drawablesArray);
if (ids.length != drawables.length() && ids.length != names.length) {
Log.e("ICONS_SELECT", "convertResourceArraysToIconsArrayList(): Arrays must have equals lengths!");
return null;
}
//create ArrayList
ArrayList<SelectableIcon> result = new ArrayList<>();
for (int i = 0; i < ids.length; i++) {
result.add(new SelectableIcon(ids[i], names[i], drawables.getResourceId(i,-1)));
}
//sort by names
if (sortByName) {
Collections.sort(result, new SelectableItemNameComparator<SelectableIcon>());
}
return result;
}
Wonderful library! But... I can't set icons for IconChooseDialog with this method:
If i use sampleIcons() method (as in example), then all is ok.
My arrays.xml: