Сохранение состояния проверки элемента expandableCheckRecyclerView для каждого элемента во фрагменте

Проблема: не удалось восстановить элемент состояния проверки в каждой группе.

При каждом состоянии проверки true я сохраняю данные в базе данных. Есть ли способ сохранить состояние проверки каждого элемента.

Fragment.java

adapter = new MultiCheckExpertiseAdapter(makeMultiCheckGenres());
   adapter.setChildClickListener(new OnCheckChildClickListener() {
       @Override
       public void onCheckChildCLick(View v, final boolean checked, final CheckedExpandableGroup group, int childIndex) {



       for (int x = 0; x < group.getItems().size(); x++) {

           //get the checked childs in a Group
           if (group.selectedChildren[x]) {
               ExpertiseModel model = (ExpertiseModel) group.getItems().get(x);

               if (checked)
                   common.expertise.child("7297905256").child(group.getTitle()).child(String.valueOf(model.getName())).setValue(x);

               else
                   common.expertise.child("7297905256").child(group.getTitle()).child(model.getName()).removeValue();

           }

       }
          }

});

ExpertiseDataFactory.java

package com.multirest.vishalverma.tutoredhusk.Model.ExpertiseSubModelPkg;

import com.multirest.vishalverma.tutoredhusk.Model.MultiCheckGenre;
import com.multirest.vishalverma.tutoredhusk.R;

import java.util.Arrays;
import java.util.List;

public class ExpertiseDataFactory {



  public static List<MultiCheckGenre> makeMultiCheckGenres() {
    return Arrays.asList(makeMultiCheckRockGenre(),
        makeMultiCheckJazzGenre(),
        makeMultiCheckClassicGenre(),
        makeMultiCheckSalsaGenre(),
        makeMulitCheckBluegrassGenre(),
            makeMultiCheckClassicGenre1(),
            makeMultiCheckSalsaGenre1(),
            makeMulitCheckBluegrassGenre1());
  }


  public static MultiCheckGenre makeMultiCheckRockGenre() {
    return new MultiCheckGenre("Pre Primary", makeRockArtists(), R.drawable.ic_face_gray_24dp);
  }

//  public static SingleCheckGenre makeSingleCheckRockGenre() {
//    return new SingleCheckGenre("Rock", makeRockArtists(), R.drawable.ic_electric_guitar);
//  }

  public static List<ExpertiseModel> makeRockArtists() {
    ExpertiseModel abacus = new ExpertiseModel("Abacus", false);
    ExpertiseModel handwriting = new ExpertiseModel("Handwriting Basic", false);
    ExpertiseModel english = new ExpertiseModel("English", false);
    ExpertiseModel kg = new ExpertiseModel("KG Academic Class", false);

    return Arrays.asList(abacus, handwriting, english, kg);
  }



  public static MultiCheckGenre makeMultiCheckJazzGenre() {
    return new MultiCheckGenre("Class 6 to 10", makeJazzArtists(), R.drawable.ic_face_gray_24dp);
  }
//
//  public static SingleCheckGenre makeSingleCheckJazzGenre() {
//    return new SingleCheckGenre("Jazz", makeJazzArtists(), R.drawable.ic_saxaphone);
//  }

  public static List<ExpertiseModel> makeJazzArtists() {
    ExpertiseModel all = new ExpertiseModel("All Subject", false);
    ExpertiseModel Mathematics = new ExpertiseModel("Mathematics", false);
    ExpertiseModel science = new ExpertiseModel("Science", false);
    ExpertiseModel computer = new ExpertiseModel ("Computer Science", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel hindi = new ExpertiseModel ("Hindi", false);
    ExpertiseModel social_science= new ExpertiseModel ("Social Science", false);
    ExpertiseModel sanskrit = new ExpertiseModel ("Sanskrit", false);
    ExpertiseModel environmental_studies = new ExpertiseModel ("Environmental Studies", false);
    ExpertiseModel french = new ExpertiseModel ("French", false);
    ExpertiseModel german = new ExpertiseModel ("German", false);
    ExpertiseModel spanish = new ExpertiseModel ("Spanish", false);
    ExpertiseModel mscombo = new ExpertiseModel ("Mathematics - Science (Combo)", false);
    ExpertiseModel olympaid = new ExpertiseModel ("Olympiad Maths/Science", false);
    return Arrays.asList(all, Mathematics, science,computer,english,hindi,social_science,sanskrit,environmental_studies,french,german,spanish,mscombo,olympaid);
  }



  public static MultiCheckGenre makeMultiCheckClassicGenre() {
    return new MultiCheckGenre("Class 11 Arts", makeClassicArtists(), R.drawable.ic_face_gray_24dp);
  }


  public static List<ExpertiseModel> makeClassicArtists() {
    ExpertiseModel geography = new ExpertiseModel ("Geography", false);
    ExpertiseModel history = new ExpertiseModel ("History", false);
    ExpertiseModel political_science = new ExpertiseModel ("Political Science", false);
    ExpertiseModel humanities = new ExpertiseModel ("Humanities", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel psychology = new ExpertiseModel ("Psychology", false);
    ExpertiseModel computer = new ExpertiseModel ("Computer Science/Information Practices", false);

    return Arrays.asList(geography, history, political_science, humanities,english,psychology,computer);
  }


  public static MultiCheckGenre makeMultiCheckSalsaGenre() {
    return new MultiCheckGenre("Class 11 Commerce", makeSalsaArtists(), R.drawable.ic_face_gray_24dp);
  }



  public static List<ExpertiseModel> makeSalsaArtists() {
    ExpertiseModel accounts = new ExpertiseModel ("Accounts", false);
    ExpertiseModel business_studies = new ExpertiseModel ("Business Studies", false);
    ExpertiseModel economics = new ExpertiseModel ("Economics", false);
    ExpertiseModel mathematics = new ExpertiseModel ("Mathematics", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel psychology = new ExpertiseModel ("Psychology", false);
    ExpertiseModel environmental_studies = new ExpertiseModel ("Environmental Studies", false);
    ExpertiseModel computer = new ExpertiseModel ("Computer Science/Information Practices", false);


    return Arrays.asList(accounts, business_studies, economics, mathematics,english,psychology,environmental_studies,computer);
  }


  public static MultiCheckGenre makeMulitCheckBluegrassGenre() {
    return new MultiCheckGenre("Class 11 Science", makeBluegrassArtists(), R.drawable.ic_face_gray_24dp);
  }


  public static List<ExpertiseModel> makeBluegrassArtists() {
    ExpertiseModel mathematics = new ExpertiseModel ("Mathematics", false);
    ExpertiseModel physics = new ExpertiseModel ("Physics", false);
    ExpertiseModel chemistry = new ExpertiseModel ("Chemistry", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel pcb_combo = new ExpertiseModel ("PCB Combo", false);
    ExpertiseModel pcm_combo = new ExpertiseModel ("PCM Combo", false);
    ExpertiseModel cs= new ExpertiseModel ("Computer Science/Information Practices", false);
    ExpertiseModel ce = new ExpertiseModel ("Competitive Exam Preparation", false);

    return Arrays.asList(mathematics, physics, chemistry, english,pcb_combo,pcm_combo,cs,ce);
  }


  public static MultiCheckGenre makeMultiCheckClassicGenre1() {
    return new MultiCheckGenre("Class 11 Arts", makeClassicArtists1(), R.drawable.ic_face_gray_24dp);
  }


  public static List<ExpertiseModel> makeClassicArtists1() {
    ExpertiseModel geography = new ExpertiseModel ("Geography", false);
    ExpertiseModel history = new ExpertiseModel ("History", false);
    ExpertiseModel political_science = new ExpertiseModel ("Political Science", false);
    ExpertiseModel humanities = new ExpertiseModel ("Humanities", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel psychology = new ExpertiseModel ("Psychology", false);
    ExpertiseModel computer = new ExpertiseModel ("Computer Science/Information Practices", false);

    return Arrays.asList(geography, history, political_science, humanities,english,psychology,computer);
  }


  public static MultiCheckGenre makeMultiCheckSalsaGenre1() {
    return new MultiCheckGenre("Class 11 Commerce", makeSalsaArtists1(), R.drawable.ic_face_gray_24dp);
  }



  public static List<ExpertiseModel> makeSalsaArtists1() {
    ExpertiseModel accounts = new ExpertiseModel ("Accounts", false);
    ExpertiseModel business_studies = new ExpertiseModel ("Business Studies", false);
    ExpertiseModel economics = new ExpertiseModel ("Economics", false);
    ExpertiseModel mathematics = new ExpertiseModel ("Mathematics", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel psychology = new ExpertiseModel ("Psychology", false);
    ExpertiseModel environmental_studies = new ExpertiseModel ("Environmental Studies", false);
    ExpertiseModel computer = new ExpertiseModel ("Computer Science/Information Practices", false);


    return Arrays.asList(accounts, business_studies, economics, mathematics,english,psychology,environmental_studies,computer);
  }


  public static MultiCheckGenre makeMulitCheckBluegrassGenre1() {
    return new MultiCheckGenre("Class 11 Science", makeBluegrassArtists1(), R.drawable.ic_face_gray_24dp);
  }


  public static List<ExpertiseModel> makeBluegrassArtists1() {
    ExpertiseModel mathematics = new ExpertiseModel ("Mathematics", false);
    ExpertiseModel physics = new ExpertiseModel ("Physics", false);
    ExpertiseModel chemistry = new ExpertiseModel ("Chemistry", false);
    ExpertiseModel english = new ExpertiseModel ("English", false);
    ExpertiseModel pcb_combo = new ExpertiseModel ("PCB Combo", false);
    ExpertiseModel pcm_combo = new ExpertiseModel ("PCM Combo", false);
    ExpertiseModel cs= new ExpertiseModel ("Computer Science/Information Practices", false);
    ExpertiseModel ce = new ExpertiseModel ("Competitive Exam Preparation", false);

    return Arrays.asList(mathematics, physics, chemistry, english,pcb_combo,pcm_combo,cs,ce);
  }
}

Viewholder.java // видоискатель, который связывает все виды вместе

public MultiCheckExpertiseAdapter(List<MultiCheckGenre> groups) {
    super(groups);
  }

  @Override
  public MultiCheckExpertiseViewHolder onCreateCheckChildViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.expertise_ui, parent, false);
    return new MultiCheckExpertiseViewHolder(view);
  }

  @Override
  public void onBindCheckChildViewHolder(MultiCheckExpertiseViewHolder holder, int position,
                                         CheckedExpandableGroup group, int childIndex) {
    final ExpertiseModel artist = (ExpertiseModel) group.getItems().get(childIndex);
    holder.setArtistName(artist.getName());

  }

  @Override
  public GenreViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
        .inflate(R.layout.list_item_genre, parent, false);
    return new GenreViewHolder(view);
  }

  @Override
  public void onBindGroupViewHolder(GenreViewHolder holder, int flatPosition,
      ExpandableGroup group) {
    holder.setGenreTitle(group);

  }

/// Я могу выполнить проверку - снимите флажок с каждого элемента, но не могу восстановить состояние каждого элемента.

0 ответов

Другие вопросы по тегам