0

i currently have a divider for each of my item in the expandablelistview

<View android:id="@+id/divider"
        android:layout_height="1dp"
        android:layout_width="match_parent"
        android:background="@drawable/your_divider"
        android:layout_alignBottom="@+id/parent_layout_id"/>

What i want to do is to remove the divider of each last item in the Group. So the last item in group 1 shouldn't have a divider, the last item in group 2 shouldn't also have a divider.

Currently my code is like this:

public View getChildView(int posParent, int posChild, boolean isLastChild, View view, ViewGroup viewGroup) {

        final AccountBalanceItem expandedListText = (AccountBalanceItem) getChild(posParent, posChild);
        if (view == null) {
            LayoutInflater layoutInflater = (LayoutInflater) mContext
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            view = layoutInflater.inflate(R.layout.card_account, null);
                    View divider = (View) view
                .findViewById(R.id.divider);
        if (isLastChild) {
            divider.setVisibility(View.GONE);
        }
     }

My current code only hides the last item in the Group 2, my last item in the Group 1 still have an divider which is wrong. Both last item of group 1 and 2 shouldn't have a divider.

KikX
  • 217
  • 2
  • 17

1 Answers1

2

Try: find divider outside if (view == null) { } and always setVisibility

public View getChildView(int posParent, int posChild, boolean isLastChild, View view, ViewGroup viewGroup) {

    final AccountBalanceItem expandedListText = (AccountBalanceItem) getChild(posParent, posChild);
    if (view == null) {
        LayoutInflater layoutInflater = (LayoutInflater) mContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = layoutInflater.inflate(R.layout.card_account, null);
    }
    View divider = (View) view.findViewById(R.id.divider);
    if (isLastChild) {
        divider.setVisibility(View.GONE);
    } else {
        divider.setVisibility(View.VISIBLE);
    }
    return view;
 }

Hope that helps!

i_A_mok
  • 2,744
  • 2
  • 11
  • 15