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

Asked

Viewed 67 times

0

Good am with the following problem, I used a layout inflater to fill a listview with a adapter but I want to clean this adapter, because the products contained in the list does not change when I click on another category of products, Example: appears the categories and when clicking on a category list the products related to it but when I click on another category appears the same products, someone has an idea of how to clean the layout inflater or the adapter because I don’t know where to make this modification.

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 listdapter:

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;
        }
    }
  • And where are you changing the dt?

  • In oncliki when cliko in a category he changes dt by calling a method that loads it with the information and passes it to Adapter and then to the list.

1 answer

0

In oncliki when cliko in a category he changes dt by calling a method that loads it with the information and passes it to Adapter and then to the list.

Browser other questions tagged

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