Inserting bank value in ExpandableListView via hasmap

1

I'm having trouble inserting values in the ExpandableListView of the SQLite Android database.

In my app, I have a main table called DISCIPLINES and another table that has a foreign key reference to this main, called NOTES.

In my ExpandableListView, group is being populated by the DISCIPLINE table of the database, which are values already defined in an earlier step in my application. So far so good, the problem comes up when I need to populate the childrens , these childrens need to be filled according to the discipline that will be selected via ExpandableListView >. And I'm trying to do this via HashMap.

I think my problem is in logic, but I have already tried several ways to do this, if anyone can help me or even talk about another way to do it, I thank you.

ExpandableAdapter class:

'public class ExpandableAdapter extends BaseExpandableListAdapter {

private List<Disciplina> listGroup;
private HashMap<Disciplina, List<Nota>> listData;
private LayoutInflater inflater;
private Nota nota = new Nota();
private Disciplina disciplina = new Disciplina();
Context context;

public ExpandableAdapter(Context context, List<Disciplina> listGroup, HashMap<Disciplina, List<Nota>> listData){
    this.listGroup  = listGroup;
    this.listData = listData;
    this.context = context;
    inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

}

@Override
public int getGroupCount() {
    return listGroup.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    if(listData.size() == 0){
        Toast toast = Toast.makeText(context, "Não há notas nesta disciplina", Toast.LENGTH_SHORT);
        toast.show();

        return 0;
    }
    else{
        return listData.get(listGroup.get(groupPosition)).size();
    }
}

@Override
public Object getGroup(int groupPosition) {
    return listGroup.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {
    return listData.get(listGroup.get(groupPosition)).get(childPosition);
}

@Override
public long getGroupId(int groupPosition) {
    return listGroup.get(groupPosition).getId();
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return listData.get(listGroup.get(groupPosition)).get(childPosition).getId();
}

@Override
public boolean hasStableIds() {
    return true;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    final ViewHolderGroup holder;

    if(convertView == null) {
        convertView = inflater.inflate(R.layout.header_expandable_list_view, null);
        holder = new ViewHolderGroup();
        convertView.setTag(holder);

        holder.txtGroup = (TextView) convertView.findViewById(R.id.txtGroup);
        //holder.imbOpcoes = (Button) convertView.findViewById(R.id.imbOpcoes);
    }else{

        holder = (ViewHolderGroup) convertView.getTag();
    }

    disciplina = listGroup.get(groupPosition);
    holder.txtGroup.setText(String.valueOf(disciplina.getAbreviacao()));

    return convertView;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {

    ViewHolderItem holder;

    if(convertView == null) {
        convertView = inflater.inflate(R.layout.item_expandable_list_view, null);
        holder = new ViewHolderItem();
        convertView.setTag(holder);

        holder.txtItem = (TextView) convertView.findViewById(R.id.txtItem);
    }else{

        holder = (ViewHolderItem) convertView.getTag();
    }

    nota = listData.get(listGroup.get(groupPosition)).get(childPosition);

    holder.txtItem.setText(String.valueOf(nota.getNota()));

    return convertView;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

class ViewHolderGroup {

    TextView txtGroup;
}

class ViewHolderItem {

    TextView txtItem;
}'

Last method I tried to insert notes:

    public void construirLista(){

    listGroup = new ArrayList<Disciplina>();
    listData = new HashMap<Disciplina, List<Nota>>();
    ArrayList<Nota> auxilirList = new ArrayList<Nota>();
    ArrayList<Nota> arrayNota = new ArrayList<Nota>();
    ArrayList<Disciplina> arrayDisciplina = new ArrayList<Disciplina>();

    nota = new Nota();
    disciplina = new Disciplina();
    repositorioDisciplina = new RepositorioDisciplina(conn);

    listGroup = repositorioDisciplina.buscaDisciplina(0);
    disciplina = listGroup.get(0);

    for(int f = 0; f < listGroup.size(); f++) {

        for(int j = 0; j < arrayNota.size(); j++){

            nota = arrayNota.get(j);

            auxilirList = repositorioNota.buscarNota(this, nota.getId_disciplina());//busca as NOTAS pelo ID da disciplina
            arrayDisciplina = repositorioDisciplina.buscaDisciplina(nota.getId_disciplina());

            disciplina = arrayDisciplina.get(0);
        }

        listGroup.add(disciplina);
        listData.put(disciplina, auxilirList);
    }
}
    
asked by anonymous 13.11.2017 / 22:04

0 answers