Get childView position in Expandablelistview

Asked

Viewed 58 times

0

I have a Expandablelistview in my app.

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:id="@+id/myLayout"
    android:layout_height="match_parent"
    android:layout_weight="1">

    <ExpandableListView
        android:id="@+id/expandableListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="4dp"
        />

</LinearLayout>

I create Groups and Children dynamically. So far so good.

Only that I need to click on a child of a certain Group (onChildClick), move on to the next child of that same group clicked. By clicking on a particular child of a group, it will advance (scroll) to the next child of that same group that I’m in and not to the next group of Expandablelistview.

How to scroll Expandablelistview to the next child of the group I’m focused on?

I hope I explained my doubt well.

1 answer

1


Be able to solve this problem with the ScrollView even.

I have an activity where I use a scrollview:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:layout_weight="1">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tb_pergunta"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize" />

        <TableLayout
            android:id="@+id/tl_principal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </TableLayout>

        <ScrollView
            android:id="@+id/sv_table"
            android:layout_height="700dp"
            android:scrollbars="horizontal|vertical"
            android:layout_width="match_parent"
            android:layout_marginTop="5dip"
            android:scrollbarStyle="outsideInset"
            android:fillViewport="true">

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:id="@+id/myLayout"
                android:layout_height="match_parent"
                android:layout_weight="1">

            </LinearLayout>
        </ScrollView>
</LinearLayout>

Within the LinearLayout of ScrollView i assign "n" dynamically created layouts. So with that, I don’t have a layout set to put inside the ScrollView.

These dynamic Layouts also get children of various types of widgets (RadioButton, CheckBox, EditText, TextView, etc.).

As they are created dynamically, they do not have a certain position within the LinearLayout father. With this, I had a lot of trouble rolling the ScrollView even those children.

Getting the position of the parent Layouts was easy as it was only getting by catching the childAt(Indice) from LinearLayout main (what is inside the ScrollView).

posicaoPai = lnPrincipal.getTop();

But until I rolled into the position of the children, I penetrated.

At last. The way I found to roll up to the children was to get the top position of "lnPai.getTop()" and the top position of the children inside it.

posicaoFilho = lnFilho.getTop();

I added the father’s position to the son’s position:

posicaoScrol = posicaoPai + posicaoFilho;

And with that I got the son’s position inside the ScrollView which would equal the Top position of the Parent Layout with the Top position of the Son.

After that, just go to the ScrollView the position of the child that was found in the sum above.

final int posicaoArray = arrayFilhoOpcao.get(contArray_z + 1);
myScrollLayout.post(new Runnable() {
    @Override
    public void run() {
        myScrollLayout.smoothScrollTo(0, posicaoArray);
    }
});

The ArrayList I created to put all the positions of the children of the Layout that I am currently browsing.

Well... I hope it fits someone and that if it seems silly to others, many beginners like me sometimes have a hard time finding solutions to problems that would be simple for others.

  • 1

    Thanks again my friend.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.