質問

I am working with BaseExpandableListAdapter and cannot really undertstand why the method getChildId(int groupPosition, int childPosition) loops three times when I click the one and only child that exists in that groupposition?

I want something to happend when the childitem is clicked but the problem is that the program executes that three times, despite I only have one child.

Through System.out.println("")` one can see that the string is printed 3 times. why?

Maybe I missed something crucial? Should I use another method for intance?

Cincerely Björn

    public long getChildId(int groupPosition, int childPosition) {
          System.out.println("childPosition: " + childPosition + " groupPosition: " + groupPosition);

          switch (childPosition) {
            case 0:
                // Do something
                break;
            case 1: 
                // Do something
                break;
          }

    return 0;
}
役に立ちましたか?

解決

enter code hereYou are not supposed to do anything in getChildId you should only return the id. You should do everything in ExpandableListActivity.onChildClick and such.

That is, getChildId should not change the state of your program. Because it can be called arbitrarily by the Android framework.

Just return something like groupPosition*100 + childPosition. Then in ExpandableListActivity.onChildClick and such you can figure out the id by the same formula.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top