-1

hope you fine and well

suppose i have the following class :

public class MainActivity extends AppCompatActivity {

public  List<Student> DisplyOnTextView( List< Student > students) {
        return students;


    }
}

the function is receive the List student.

and suppose that i have also the following class :

   public class CustomAdapter extends PagerAdapter {

        public Object instantiateItem(ViewGroup container, int position) {


    }

  }

how i can return the List students from the function of the first class to the function in the second class ?

regards .

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
MSMC
  • 141
  • 1
  • 5
  • 16
  • Possible duplicate of [Passing ArrayList from AsyncTask to PagerAdapter](http://stackoverflow.com/questions/36828583/passing-arraylist-from-asynctask-to-pageradapter) – OneCricketeer Apr 30 '16 at 15:39

1 Answers1

1

Create a constructor for the CustomAdapter class that accepts the list as parameters, and save the passed value as in a field.

public class CustomAdapter extends PagerAdapter {

    private List<Student> mData;

    public CustomAdapter(List<Student> students) {
        super();
        mData = students;
    }    

}
Danail Alexiev
  • 7,624
  • 3
  • 20
  • 28
  • thank you , but to make things clear, i want the List from the function of the first class to be accessed in the function of the second class , i used your code but when i use mDdata the application says : unfortunately stopped. – MSMC Apr 25 '16 at 15:30
  • Make sure that you are not passing `null` to the constructor. Check your exception message, see what's the problem and deal with it. The provided code is just an example, don't expect it to fit right into your app and work from the first run. – Danail Alexiev Apr 25 '16 at 15:36