lundi 29 juin 2015

Invisible android.support.v4.app.Fragment on Android 5.1


I have got a problem. I have written an android app that uses fragments. I created fragments in a loop and they are visible on android 2.2 but not on android 5.1! I could not find out what is my mistake although I was looking for answers a lot. I hope you can help me. (Don't worry about the words in the frame they are a german timetable ;) )

enter image description here

public void setInfo(String date, ArrayList<Lesson> l) {
    TextView dv = (TextView) getActivity().findViewById(R.id.dayview);
    dv.setText(date);
    LinearLayout ll = (LinearLayout) getActivity().findViewById(R.id.lessonlayout);
    ll.removeAllViews();
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    for(int i = 0; i < l.size(); i ++) {
        Log.d("GCG", "Fragment: " + Integer.toString(i));
        Fragment lf = new LessonFragment(l.get(i));
        fragmentTransaction.add(R.id.lessonlayout, lf);
    }
    fragmentTransaction.commit();
}

This method loads the fragments. Lesson is a my class to save information and is not important.

And here is my class LessonFragment:

public class LessonFragment extends Fragment {

    private Lesson lesson;

    public LessonFragment(Lesson l) {
        lesson = l;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.fragment_lesson, container, false);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        Log.d("GCG", "on View Created!");
        TextView tlesson = (TextView) view.findViewById(R.id.lesson);
        TextView tsubject = (TextView) view.findViewById(R.id.subject);
        TextView troom = (TextView) view.findViewById(R.id.room);
        TextView tteacher = (TextView) view.findViewById(R.id.teacher);
        TextView tinformations = (TextView) view.findViewById(R.id.informations);

        tlesson.setText(lesson.getNumber());
        tsubject.setText(lesson.getSubject());
        troom.setText(lesson.getRoom());
        tteacher.setText(lesson.getTeacher());
        tinformations.setText(lesson.getInformation());
    }

    @Override
    public void onStart() {
        super.onStart();
    }
}


Aucun commentaire:

Enregistrer un commentaire