Clear a listview that is inflated with an inflater layout, Android C #

0

Well, I'm having the following problem, I used a inflater map to fill a listview with a adapter but I want to clear that adapter , since the products contained in the list do not change when I click another category of products, Example: categories appear and clicking on a category lists the products related to it but when I click on another category the same products appear, someone has an idea how to clean the layout inflater or adapter because I I do not know where to make this change.

My activymain code:

var cateListView = FindViewById<ListView>(Resource.Id.listViewcategorias);
                    //Toast.MakeText(this, dt.Rows.Count.ToString(), ToastLength.Short).Show();
                    cateListView.FastScrollEnabled = true;
                    // cateListView.ItemClick += FilmesListView_ItemClick;
                    categoriasAdapter.dt = dt;
                    var filmesAdapter = new categoriasAdapter(this, FilmesRepositorio.cate);   
                    cateListView.Adapter = filmesAdapter;
                    cateListView.ItemClick += FilmesListView_ItemClick;

My listadapter:

public class produtoAdapter : BaseAdapter<produto>
    {
        private readonly Activity context;
        private readonly List<produto> prod;
        public static DataTable dt = new DataTable();
        public produtoAdapter(Activity context, List<produto> pro)
        {
            this.context = context;
            this.prod = pro;

        }
        public override produto this[int position]
        {
            get
            {
                return prod[position];
            }
        }

        public override int Count
        {
            get
            {
                return prod.Count;
            }
        }



        public override long GetItemId(int position)
        {
            return prod[position].Id_prod;
        }

        public override View GetView(int position, View convertView, ViewGroup parent)
        {
            //context.Recreate();
            //var view = convertView ?? context.LayoutInflater.Inflate(Resource.Layout.vprodutos, parent, false);  
            context.LayoutInflater.Dispose();
            var view = convertView = this.context.LayoutInflater.Inflate(Resource.Layout.vprodutos, parent, false);
            try
            { 
                var txtproduto = view.FindViewById<TextView>(Resource.Id.txtproduto);
                var txtvalorproduto = view.FindViewById<TextView>(Resource.Id.txtvalorproduto);
                txtproduto.Text = prod[position].descricao;
                txtvalorproduto.Text = prod[position].valor.ToString("0.00");
                Toast.MakeText(Application.Context, "adiconou" + prod[position].descricao, ToastLength.Short).Show(); 
            }
            catch (Exception ex)
            {
                Toast.MakeText(Application.Context, ex.ToString(), ToastLength.Short).Show();
            }
            return view;
        }
    }
    
asked by anonymous 21.12.2018 / 17:15

1 answer

0

In the oncliki when cliko in a category it change the dt calling a method that loads it with the information and pass to the adapter and then to the list.

    
28.12.2018 / 03:41