Expandablelistview Com Formulario

Asked

Viewed 145 times

1

I would like to know how I can use an Expandablelistview with a form instead of just text. By expanding Expandablelistview instead of coming varies lines with only texts I can put several different edittext to fill in. I would like to use to split data types as first "tab" customers second address. I hope I have been clear in my doubt.

  • It is possible... But what is the need to be one ExpandableListView? You could, for example, create a "hidden" layout below each form session and animate according to the tap on the component

  • @sicachester well would not have well to be a expandableListView but as I do not have much knowledge on android I thought it would be the simplest solution because I do not want to have to work with more than one Activity to treat these editext. If you have another solution I am listening. I just don’t want the user to have to scroll a very large form, so I would like to split.

  • I answered with a solution! See if it meets

1 answer

1


You can do with the Transitionmanager, but is only available in API 19.

A solution, something like this

1- In your layout, put inside some container (Relativelayout, Linearlayout, Framelayout etc.) what 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));
}

Browser other questions tagged

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