Zakri Vorschted
Zakri Vorschted

Reputation: 11

Updating ListView inside Fragment (ViewPager)

i've a simple chat application with ViewPager for Active Chats, now, i use

    @Override
    public int getItemPosition(Object object)
    {
        return POSITION_NONE;
    }

but this causes the all fragments to be recreated, and if there is too many messages it will lag, and also it closes keyboard whenever a message is received, so i attempted to override instantiateItem, but i couldn't get to anywhere, since i didn't know what to do with it, i wanted to update all listviews/fragments, not just the active one.

i also tried to use the onCreateView of fragments, get the listview, add an adapter to it, and add that adapter to a Array list, and whenever each messages comes, all adapters in this array list are updated, but this didn't work as expected, i had to move away from ViewPager then back to it again (Since the ViewPager is inside a tabHost) for messages to be displayed.

any help is appreciated, thanks.

Upvotes: 1

Views: 2746

Answers (1)

Marcin S.
Marcin S.

Reputation: 11191

Please use setTag() method in getItemPostion() for the views to update them rather then returning POSITION_NONE. The reason of using setTag() and the way how to do that is well explained in this post ViewPager PagerAdapter not updating the View

Upvotes: 1

Related Questions