Get childView position in ExpandableListView

0

I have an 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.

I just need to click on a child of a certain group ( onChildClick ), move on to the next child of that group clicked. When clicking on a given child in a group, it will scroll to the next child of that same group that I am and not to the next group in the ExpandableListView.

How can I scroll the ExpandableListView to the next child in the group I'm focused on?

I hope I have explained my question well.

    
asked by anonymous 11.04.2016 / 17:25

1 answer

1

Can solve this problem with ScrollView same.

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 LinearLayout of ScrollView I assign "n" Layouts created dynamically. So with that, I do not have a layout set to place within ScrollView .

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

Because they are dynamically created, they do not have a right position within the LinearLayout parent. With that, I had a hard time rolling down ScrollView to those children.

Getting the position of the parent Layouts was easy, as it was only by getting the childAt (index) from the LinearLayout parent (which is within ScrollView ).

posicaoPai = lnPrincipal.getTop();

But until you roll into the position of the children, I have sifted.

Finally. The way I found to scroll up to the children was to get the top position of the "lnPai.getTop ()" and the top position of the children that are inside it.

posicaoFilho = lnFilho.getTop();

Add the position of the father with the position of the child:

posicaoScrol = posicaoPai + posicaoFilho;

And with that I got the position of the child within ScrollView that would equal the Top position of the parent Layout with the top position of the child.

After this, just move to the ScrollView 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'm currently browsing.

Well ... I hope it works for someone and 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.

    
13.04.2016 / 13:26