ExpandableListView With Form

1

I would like to know how I can use an ExpandableListView with a form instead of just text. When I expand the ExpandableListView instead of varying lines with just texts I can put several different edittext to fill. I would use to split data types as the first "tab" clients second address. I hope I was clear in my doubt.

    
asked by anonymous 22.12.2014 / 14:56

1 answer

1

You can do with TransitionManager , but it is only available in API 19.

One solution would be something like this

1- In your layout, place a container (RelativeLayout, LinearLayout, FrameLayout, etc.) in the container you want to hide / show. You can set the click to the entire component, or with a button, as you prefer:

<RelativeLayout
    android:id="@+id/touchAreaRelativeTest"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <Button
        android:id="@+id/btTouchToOpen"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Toque para abrir" />

    <!-- Layout a ficar escondido -->
    <RelativeLayout
        android:id="@+id/linearOpen"
        android:layout_below="@id/btTouchToOpen"
        android:layout_width="match_parent"
        android:orientation="vertical"
        android:animateLayoutChanges="true"
        android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/linearOne"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Titulo"
                android:textSize="16sp" />

            <EditText
                android:layout_marginLeft="8dp"
                android:id="@+id/etOne"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

        <LinearLayout
            android:layout_below="@+id/linearOne"
            android:id="@+id/linearTwo"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Titulo"
                android:textSize="16sp" />

            <EditText
                android:layout_marginLeft="8dp"
                android:id="@+id/etTwo"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </LinearLayout>

    </RelativeLayout>

</RelativeLayout>

In your Fragment or Activity:

private RelativeLayout linearAction;
private int valueHeight;

...

linearAction = (RelativeLayout) view.findViewById(R.id.linearOpen);

//Definindo a altura do seu componente como 0.
RelativeLayout.LayoutParams paramsList = (RelativeLayout.LayoutParams) linearAction.getLayoutParams();
if (paramsList != null)
    paramsList.height = 0;

//Retendo a altura do seu componente para a animação
valueHeight = linearAction.getHeight();
if (valueHeight == 0f) {
    linearAction.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    valueHeight = linearAction.getMeasuredHeight();
}

/*
* Aqui você pode utilizar seu proprio tempo de animação. Mas o Android já tem inteiros definidos para isso.
* sendo: config_shortAnimTime, config_mediumAnimTime e config_longAnimTime
*/
final int animationTime = getResources().getInteger(android.R.integer.config_shortAnimTime);

Button btOpenView = (Button) view.findViewById(R.id.btTouchToOpen);
btOpenView.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        animateViewHeight(valueHeight, linearAction, animationTime);
    }
});

...  

/**
 * Animando a altura do seu componente
 *
 * @param deltaToAnimate Tamanho a ser animado
 * @param view           View para fazer a animação
 * @param animationTime  Tempo de duração da animação
 */
private void animateViewHeight(final int deltaToAnimate, final View view, int animationTime) {

    //Verificando se a view já está aberta.
    final boolean isViewToAnimateShowed = Boolean.valueOf((String) view.getTag());

    final ViewGroup.LayoutParams params = view.getLayoutParams();

    ValueAnimator animator = ValueAnimator.ofInt(deltaToAnimate);
    animator.setDuration(animationTime);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                                   @Override
                                   public void onAnimationUpdate(ValueAnimator animation) {
                                       int finalValue;
                                       //Caso esteja aberta, faz a animacao para fecha-la
                                       if (isViewToAnimateShowed)
                                           finalValue = deltaToAnimate - Math.round(animation.getAnimatedFraction() * deltaToAnimate);
                                       else
                                           finalValue = Math.round(animation.getAnimatedFraction() * deltaToAnimate);

                                       if (params != null) {
                                           params.height = finalValue;
                                           view.setLayoutParams(params);
                                       }
                                   }
                               }
    );
    animator.start();

    //Informando se a view esta aberta ou não
    view.setTag(String.valueOf(!isViewToAnimateShowed));
}
    
23.12.2014 / 13:18