0

I´m using a CursorTreeadapter to inflate a ExpandableListView with data from a sql database, but it's not working correctly and I hope you can help me.

public class ExplistviewAdapter extends CursorTreeAdapter {

Context mContext;

public ExplistviewAdapter(Cursor cursor, Context context) {
    super(cursor, context);
    mContext = context;
}

@Override
protected Cursor getChildrenCursor(Cursor groupCursor) {
    return groupCursor;
}


@Override
protected View newGroupView(Context context, Cursor cursor, boolean isExpanded, ViewGroup parent) {

    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = layoutInflater.inflate(R.layout.borderslayout,parent, false);

    return view;
}

@Override
protected void bindGroupView(View view, Context context, Cursor cursor, boolean isExpanded) {

    //bind existing views with data from cursor ...
    TextView measuredate = (TextView) view.findViewById(R.id.datumTF);
    //.......
    //......
}


@Override
protected View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) {

        final View view = LayoutInflater.from(context).inflate(R.layout.child_view, parent, false);
        TextView nameTV = (TextView) view.findViewById(R.id.textView11);

        return view;

}

@Override
protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) {

   //bind existing views with data from cursor ...
   Textview existingview = (Textview)    view.findViewById(R.id.existingviewTV);
   //......
   //.....
}

}

The Problem: I initialize the Class with a cursor that I received from a sql database via rawQuery. The cursor has for example 3 Rows:

   cursorROW1: measuredateROW1 LastnameRow1 SurnameRow1       
   cursorROW2: measuredateROW2 LastnameRow2 SurnameRow2              
   cursorROW3: measuredateROW3 LastnameRow3 SurnameRow3

The initialization of the Groupview works fine and the ExpandableListview consits of the 3 different tableEntries with the different measuredates. But when I expand the tableEntries each Childview contains every Lastname and Surname from the different cursorRows:

    measuredateRow1
     - LastnameRow1 SurnameRow1 
     - LastnameRow2 SurnameRow2 
     - LastnameRow3 SurnameRow3
    measuredateRow2
     - LastnameRow1 SurnameRow1 
     - LastnameRow2 SurnameRow2 
     - LastnameRow3 SurnameRow3
    measuredateRow3
     - LastnameRow1 SurnameRow1 
     - LastnameRow2 SurnameRow2 
     - LastnameRow3 SurnameRow3

But I want following behavior

  measuredateRow1
     - LastnameRow1 SurnameRow1 
  measuredateRow2
     - LastnameRow2 SurnameRow2
  measuredateRow3
     - LastnameRow3 SurnameRow3 

How can I achieve that ?

best regards.

martin
  • 151
  • 7

0 Answers0