Java.lang.runtimeexception: Illegal Position! In Tagview
Solution 1:
This error will be thrown under the following circumstances:
privatevoid onAddTag(String text, int position) {
if (position < 0 || position > mChildViews.size()) {
thrownewRuntimeException("Illegal position!");
}
From your code:
mTagContainerLayout2.addTag(selectedNames.get(i), selectedIds.get(i));
You are trying to add tags to a position which doesn't exists inside the TagView layout.
onAddTag(String text, int position)
is useful if you already have a list of TagView and you want to add a new item in between or at the end of the list.
Use
mTagContainerLayout.addTag(String text);
for adding single item.
Or
mTagContainerLayout.setTags(List<String> tags);
for adding multiple items.
How indexing works?
id
for the tags will auto increase based on indexing starting from 0. You might be wondering how to detect the MultiSelectDialog
id
along with the TagView
id
? For this you can use a HashMap
with MultiSelectDialog
id as key
and TagView
id as value
.
HashMap<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
.onSubmit(new MultiSelectDialog.SubmitCallbackListener() {
@Override
publicvoid onSelected(ArrayList<Integer> selectedIds, ArrayList<String> selectedNames, String dataString) {
//Adding tags
mTagContainerLayout2.addTag(selectedNames());
for (int i = 0; i < selectedIds.size(); i++) {
hashMap.add(selectedIds.get(i), i);
}
}
To get the id
of a TagView item by the id
of MultiSelectDialog
int selectedTagView = hashMap.get(multiSelectDialogId);
Post a Comment for "Java.lang.runtimeexception: Illegal Position! In Tagview"