we can achieve that by creating interface.

e.g

*public* *class* SampleFragment *extends* ListFragment {

    *private* OnItemSelectedListener listener;



    *public* *interface* OnItemSelectedListener {

        *public* void *onItemSelected*(int index);

    }



    *public* void *setOnItemSelectedListener*(OnItemSelectedListenerlistener
) {

        *this*.listener = listener;

    }



    @Override

    *public* void *onListItemClick*(ListView l, View v,

                                int position, long id) {

        listener.*onItemSelected*(position);

    }




Activity source code

*public* *class* MyActivity *extends* Activity

    *implements* ItemFragment.OnItemSelectedListener {


@Override

        *public* boolean *onCreate*(Bundle bundle) {

                *// ...*

                SampleFragment item = *new* *SampleFragment*();

                item.*setOnItemSelectedListener*(*this*);

                *// ...*

        }



    *public* void *onItemSelected*(int index) {

        *// ...*

    }

    *// ...*

}

Hope this snippet helps you. Good Luck


Regards

Vinay Kumar


On Sat, Sep 29, 2012 at 3:18 PM, Raneez <rane...@gmail.com> wrote:

> I use ViewPager loaded with fragments in it .The *onResume()* method of
> each fragments does some logic and so i get problems when the adjacent
> fragments(left and right) to the currently selected page are also loaded to
> provide smooth scrolling between the pages.
>
> Does the fragment recieve any *callbacks* when it get actually selected?
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to