To make an instance of a Class, you can use reflection.
Getting the class is as simple as using the get method that comes with all List implementations making sure ofcourse that the index you are accessing actually exists. After you obtain the Class object you can use reflection to instanciate it:
Example #1, No parameter constructor:
Class<?> myClass = String.class;
try {
Object objectOfClass = myClass.newInstance();
} catch (InstantiationException | IllegalAccessException e1) {
e1.printStackTrace();
}
Example #2 Constructor with parameters:
Class<?> myClass = String.class;//Get the class from the list. For this example i used String.class
try {
Constructor<?> classConstructor = myClass.getConstructor(byte[].class); //Here we get the constructor we aim for. String has a constructor which accepts a byte array as parameter, so all i do is getConstructor with patameter byte[].class.
//if your class accepts two parameters such as long and int, you will have to do .getConstructor(long.class, int.class); in the correct order ofcourse.
Object objectOfClass = classConstructor.newInstance(new byte[]{33,25,111,34});//here we call the constructor and we provide the parameter values it takes to it. So thats why i provide a byte array. In the case of the long and int constructor mentioned above, you will have to invoke it like this: .newInstance(214324324234,34242);
} catch (ReflectiveOperationException e) { //Reflective operation exception wraps up all reflection related exceptions, so we catch it instead of having to manually catch each of them.
e.printStackTrace();
}
EDIT #1 after talking with the OP in the coments, a more specific piece of code has to be provided:
// NOTE: THIS PIECE OF CODE ASUMES THAT Fragment IS THE SUPERCLASS OF ALL IMPLEMENTATIONS IN THE LIST!
List<Class<? extends Fragment>> l = new ArrayList<>();//This is your list of fragments
Fragment fragmentObject = (Fragment) l.get(3).newInstance();//use default constructor with no arguments. I am randomly getting index 3
Bundle arguments = new Bundle();
arguments.putInt("someValue",123);
fragmentObject.setArguments(arguments);