Optimization with adding list of items
In class TagView in method addTags(List<Tag> tags)you do addTag(item);
But what are doing here?
public void addTag(Tag tag) {
mTags.add(tag);
drawTags();
}
After adding of each tag to addTag you draw tags...
Inside drawTags()
first
removeAllViews();
and then
for (Tag item : mTags)
Are you jokking? Why if you are going to remove and redraw all, you do it after adding of each element to inner list?
Sorry guys but it have to be optimized!
Why if you are going to remove and redraw all, you do it after adding of each element to inner list?
I agree with you here. I don't understand it either. It's just so slow to load tags.
But I can see that was 9 months ago and no response. Why even bother...
:/ I decided to Inherit from TagView to override this method...
@Override
public void addTags(List<Tag> tags)
{
// super.addTags(tags);
try
{
Field tagsField = TagView.class.getDeclaredField("mTags");
tagsField.setAccessible(true);
ArrayList<Tag> mTags = new ArrayList<>();
Method drawTagsMethod = TagView.class.getDeclaredMethod("drawTags");
drawTagsMethod.setAccessible(true);
if (tags != null)
{
for (Tag tag : tags)
{
mTags.add(tag);
}
tagsField.set(this, mTags);
drawTagsMethod.invoke(this);
}
}
catch (NoSuchFieldException e)
{
e.printStackTrace();
}
catch (IllegalAccessException e)
{
e.printStackTrace();
}
catch (NoSuchMethodException e)
{
e.printStackTrace();
}
catch (InvocationTargetException e)
{
e.printStackTrace();
}
}