Search code examples
androidlistviewxamarin

EditText Inside a list view dissapere after inputing information


I Have a listView in which I put a ready view multiple times. This view has an edit text inside it. The problem is, when I enter values in the editext, they disappear. I guess its a focus problem but I can't figure it out.

This is the GetView method from my ListView Adapter

public override View GetView(int position, View convertView, ViewGroup parent)
        {

            LayoutInflater layoutInflater = ((RegisterActivity3)context).LayoutInflater;
            View view = layoutInflater.Inflate(Resource.Layout.seekbarvalue_template, parent, false);

            TextView tvValueName = (TextView)view.FindViewById<TextView>(Resource.Id.tvValueName);
            TextView tvAnotation = (TextView)view.FindViewById<TextView>(Resource.Id.tvAnotation);
            TextView tvMetric = (TextView)view.FindViewById<TextView>(Resource.Id.tvMetric);
            EditText etVlaue = (EditText)view.FindViewById<EditText>(Resource.Id.etValue);
            
            ValueSeekBar temp = objects[position];
            if (temp != null)
            {
                tvValueName.Text = temp.ValueName;
                tvMetric.Text = temp.Metric;
                tvAnotation.Text = temp.Anotation;
            }
            return view;

        }

video for refernce: https://im2.ezgif.com/tmp/ezgif-2-86070710e4.gif


Solution

  • You're always creating a new view. You aren't supposed to do that unless convertView is null. If convertView is not null, you're supposed to reuse that view.

    Also its recommended to just use RecyclerView rather than ListView these days.

    Example:

    public override View GetView(int position, View convertView, ViewGroup parent){
        if(convertView == null) {
            LayoutInflater layoutInflater = ((RegisterActivity3)context).LayoutInflater;
            convertView = layoutInflater.Inflate(Resource.Layout.seekbarvalue_template, parent, false);
        }
        //Now update convertView
    }