-1

And the ListView if the default ListView Whose Id is

android:id="@android:id/list"

And here is the code that i use to set Adapter

getListView().setAdapter(mAdapter);

I want to call a method after this Adapter is fully loaded.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305
Amit Sharma
  • 91
  • 1
  • 1
  • 5
  • What do you mean by fully loaded ? The adapter views keep getting recycled and I don't think there's ever a point when its 'fully loaded' – Shivam Verma Jul 09 '14 at 07:36
  • do u want to say that getView Methed of adapter class keep getting call unless the current fragment is replaced. – Amit Sharma Jul 09 '14 at 07:46
  • Yeah. The adapter keeps getting calls, that's why we first check if the convertView is null in the adapter before inflating the view. If its not, we just return that view. – Shivam Verma Jul 09 '14 at 07:48
  • @ShivamVerma Thank you very much for the help. i will find another way to solve this.. – Amit Sharma Jul 09 '14 at 07:51

1 Answers1

0

If you still need a callback to be invoked after every child view was shown to the user at least once (because it seems like that is what you want to achieve), try this tested code inside your adapter:

private boolean mFullyLoaded = false;

@Override
public View getView(int index, View convertView, ViewGroup parent) {
    if (convertView == null) {
        // inflation code here
    }
    if (!mFullyLoaded && index == getCount() - 1) {
        mFullyLoaded = true;
        // "fully loaded"-code here
    }
    return convertView;
}

The bottom if-clause is only true when the bottommost child of the ListView is displayed. At that point, as long as you didn't manually set the scroll position and thus jumped over some children, every child view was loaded/displayed at least once. The boolean-flag makes sure the code only fires once.

0101100101
  • 5,786
  • 6
  • 31
  • 55