Expandablelistview edittext disappearing or scrambling text

Asked

Viewed 44 times

0

I have a problem with Expandablelistview, I have two edittext per line, every time I type something in one, and scroll the screen, when I go back or deleted or changed position. I’ll post my code: Item_list.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <EditText
        android:id="@+id/etValorMeu"
        android:layout_width="60dp"
        android:inputType="numberDecimal"
        android:digits="0123456789.,"
        android:layout_height="wrap_content"
        android:selectAllOnFocus="true"
        android:layout_gravity="right"
        android:hint="0,00"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:id="@+id/textView2"
        android:textSize="19dp"
        android:text="Nome Produto"
        android:layout_gravity="left" />

</RelativeLayout>

acitivty_peg_values.xml:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_colocar_precos"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".Controladores.ControladorPegarPrecos">

    <LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="5">

        <ExpandableListView
            android:id="@+id/expandable_list"
            android:descendantFocusability="beforeDescendants"
            android:layout_height="match_parent"
            android:layout_below="@+id/textView"
            android:layout_above="@+id/linearLayout1"
            android:divider="#020C0D"
            android:layout_width="match_parent"/>

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:background="#DDDDDD"
            android:padding="5dp"
            android:layout_alignParentBottom="true"
            android:layout_below="@+id/ListaProdutosPrecos"
            android:elevation="0dp">
            <Button
                android:id="@+id/btnCancelar"
                android:focusable="false"
                android:focusableInTouchMode="false"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Cancelar" />

            <Button
                android:text="Salvar"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:id="@+id/btnSalvarVlr"
                android:layout_weight="1" />
        </LinearLayout>

    </LinearLayout>


</RelativeLayout>

adpaterExpandable.java:

import android.content.Context;
import android.content.SharedPreferences;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.BaseExpandableListAdapter;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.BaseExpandableListAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import applica.estudopreco.Modelos.MCotacaoItem;


public class AdapterPrecos extends BaseExpandableListAdapter {
    private Context mcontext;
    private HashMap<String, ArrayList<MCotacaoItem>> listaItens ;
    private List<String> listaCabecalho;

    LayoutInflater inflater;

    public AdapterPrecos(Context contexto, List<String> cabecalho, HashMap<String, ArrayList<MCotacaoItem>> ItensCotacao ) {
        inflater = (LayoutInflater) contexto.getSystemService(contexto.LAYOUT_INFLATER_SERVICE);
        this.mcontext = contexto;
        this.listaItens = ItensCotacao;
        this.listaCabecalho = cabecalho;
    }

    @Override
    public int getGroupCount() {
        return listaCabecalho.size();
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return listaItens.get(listaCabecalho.get(groupPosition)).size();
    }

    @Override
    public Object getGroup(int groupPosition) {
        return listaCabecalho.get(groupPosition);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {

        return listaItens.get(listaCabecalho.get(groupPosition)).get(childPosition);
    }

    @Override
    public long getGroupId(int groupPosition){
        return groupPosition;
    }

    @Override
    public long getChildId(int groupPosition, int childPosition){
        return listaItens.get(listaCabecalho.get(groupPosition)).get(childPosition).getId();
    }

    @Override
    public boolean hasStableIds(){
        return true;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent){
        ViewHolderGroup holder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.list_group, parent, false);
            holder = new ViewHolderGroup();
            convertView.setTag(holder);

            holder.tvitem = (TextView) convertView.findViewById(R.id.lblListHeader);
        }else{
            holder = (ViewHolderGroup) convertView.getTag();
        }

        holder.tvitem.setText(listaCabecalho.get(groupPosition));


        return convertView;
    }

    public View getChildView(final int groupPosition, final int childPosition, boolean isLastChild, View convertView, ViewGroup parent){

        final ViewHolderItem holder;
        MCotacaoItem val = (MCotacaoItem) getChild(groupPosition, childPosition);
        String vl = val.getoProduto().getDescricao();
        String p1 = val.getPreco1().toString();
        String p2 = val.getPreco2().toString();

        if(convertView == null){
            convertView = inflater.inflate(R.layout.precos_listview, null);
            holder = new ViewHolderItem();
            convertView.setTag(holder);

            holder.tvNome = (TextView) convertView.findViewById(R.id.textView2);
            holder.edtPr1 = (EditText) convertView.findViewById(R.id.etValorConcorrente);
            holder.edtPr2 = (EditText) convertView.findViewById(R.id.etValorMeu);
        }else{
            holder = (ViewHolderItem) convertView.getTag();
        }

        holder.tvNome.setText(vl);


        return convertView;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition){
        return true;
    }

    class ViewHolderGroup{
        TextView tvitem;
    }

    class ViewHolderItem{
        TextView tvNome;
        EditText edtPr1;
        EditText edtPr2;
        int ref;
        int re2;
    }}

1 answer

0

I solved you guys! I did it that way:

holder.edtPr2.setText(p2);
         holder.edtPr2.addTextChangedListener(new TextWatcher() {

            @Override
            public void onTextChanged(CharSequence s, int start,
            int before, int count) {
                //setting data to array, when changed
                val.setPreco2(s.toString());
            }

             @Override
             public void afterTextChanged(Editable editable) {

             }

             @Override
            public void beforeTextChanged(CharSequence s, int start,
            int count, int after) {

            }});

Browser other questions tagged

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