Edittexts dependent on an Android Gridview

Asked

Viewed 142 times

4

I have two Edittexts, a discount value, a percentage and an update Imagebutton, all are in a Gridview.

When clicking on the Imagebutton, the value entered in the percentage field should be converted to Double and assigned to the value field. The way I did, I can’t get the entered value in the percentage field.

Follow the code snippet:

@SuppressLint({ "InflateParams", "UseValueOf" })
public View getView(  final int position, View convertView, ViewGroup parent) {
    holder = null;
     if (convertView == null|| convertView.getTag()== null) {
        convertView = mInflater.inflate(R.layout.grid_itens_pedido, parent, false);

        holder = new ViewHolder();


        holder.etValorDesc.setTag(new Integer(position));
        holder.etDescontoSaida.setTag(new Integer(position));
        holder.imgAtualizar.setTag(new Integer(position));


        holder.etDescontoSaida.addTextChangedListener(new TextWatcher() {

            public void afterTextChanged(Editable s) {

               values[position].Desconto= Double.parseDouble(s.toString())/100;

            }

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


            }

            public void onTextChanged(CharSequence s, int start,
                int before, int count) {

            }

        });


        holder.imgAtualizar.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Integer position = (Integer)v.getTag();
                holder.etValorDesc.setText(String.valueOf(values[position].Desconto));


                return false;
            }
        });

1 answer

0

Switching to

if (convertView == null) {
    convertView = mInflater.inflate(R.layout.grid_itens_pedido, parent, false);

    holder = new ViewHolder();

.... resto do código aqui ...

convertView.setTag(holder);

} else {
   holder = (ViewHolder) convertView.getTag();
}

doesn’t work?

  • The converted value is being converted and assigned to the class, however, I still cannot recover this value and assign to the discount value field.

  • Not missing either : Holder.etValorDesc = (Edittext) convertView.findViewById(R.id.field_name);

  • No, I had already started this component.

Browser other questions tagged

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