How to get values from an EditText from a custom RecycleView (or ListView) in android

0

I would like you to help me with an android problem that I can not resolve. The issue is that I have a custom list with RecycleView that contains EditTexts to receive information on each of the items in the list. I need at that moment to obtain the information of each one and to verify which they were filled to work with the values received in another screen. Can you help me? Here is my try code and my main classes for that:

NoticethateachgrayboxintheQuant.(amount)ListingListCode:

<?xmlversion="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:background="@color/white"
    android:gravity="center_horizontal|center_vertical"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:orientation="horizontal"
        android:weightSum="10">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="left"
            android:layout_weight="5"
            android:background="@color/white"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/tv_compartimento"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left|center_vertical"
                android:layout_marginLeft="10dp"
                android:background="@color/white"
                android:text="Nomes dos Comodos"
                android:textColor="@color/fontBlack"
                android:textSize="18sp" />

        </LinearLayout>

        <View
            android:layout_width="1dp"
            android:layout_height="50dp"
            android:layout_gravity="center_vertical"
            android:layout_marginBottom="3dp"
            android:background="@color/grayBackground">

        </View>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_weight="5"
            android:background="@color/white"
            android:gravity="center_horizontal"
            android:orientation="horizontal">

            <EditText
                android:id="@+id/edt_cota1"
                android:layout_width="100dp"
                android:layout_height="45dp"
                android:layout_gravity="center_vertical"
                android:background="@color/newGrayBackground"
                android:hint="0"
                android:inputType="number"
                android:textAlignment="center"
                android:textColor="@color/fontGrayDark"
                android:textColorHint="@color/fontGrayDarkClaro" />

        </LinearLayout>

    </LinearLayout>

    <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="@color/grayBackground">

    </View>


</LinearLayout>

The Adapter code

import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import com.tcc.ilumina.ilumina.R;
import java.util.List;

public class RecyclerAdapter extends RecyclerView.Adapter<RecyclerAdapter.itemViewHolder>{

    private List<ObjRecycle> mObjRecycleList;
    private String[] listaComodosAtivos = new String[20];

    protected RecyclerAdapter(List<ObjRecycle> objRecycles) {
        mObjRecycleList = objRecycles;
    }


    public class itemViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        private TextView txtCompatimentos;
        private EditText edtCota1;

        private itemViewHolder(View itemView) {
            super(itemView);

            this.txtCompatimentos = itemView.findViewById(R.id.tv_compartimento);
            this.edtCota1 = itemView.findViewById(R.id.edt_cota1);
        }

        @Override
        public void onClick(View view) {

        }

    }

    @Override
    public itemViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View itemView = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.frag_row_items_lv, viewGroup, false);

        return new itemViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(itemViewHolder holder, int position) {
        ObjRecycle item = mObjRecycleList.get(position);
        holder.txtCompatimentos.setText(item.getCompatimento());
        listaComodosAtivos[position] = holder.edtCota1.getText().toString();
        Log.i("myLog", "Lista em holder: " + listaComodosAtivos[position]);

    }

    public String[] getListaComodosAtivos() {
        return listaComodosAtivos;
    }

    @Override
    public int getItemCount() {
        return mObjRecycleList.size();
    }

}

Data will be obtained when a button is pressed

proximo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String[] listaComodosSelecionados = new String[20];
                listaComodosSelecionados = adapter.getListaComodosAtivos();
                for (int i = 0; i < listaComodosSelecionados.length; i++) {
                    if (isCapomVazio(listaComodosSelecionados[i])) {
                        Log.i("myLog", "valor da lista " + listaComodosSelecionados[i]);
                    }
                    adapter.getListaComodosAtivos();
                }

                Intent intent = new Intent(getApplicationContext(), InputDataActivity.class);
                startActivity(intent);

            }
        });

        private boolean isCapomVazio(String valor) {
        boolean resultadoBoolean = (TextUtils.isEmpty(valor) ||  valor.trim().isEmpty());
        return resultadoBoolean;
        }
    
asked by anonymous 29.04.2018 / 20:04

0 answers