Reputation: 1
I have button in every item in list view when i try save last item no problem but when i try save another item it save data many times
this is my code
public override View GetView(int position, View convertView, ViewGroup parent)
{
var item = trans[position];
View view = convertView;
if (view == null) // no view to re-use, create new
view = context.LayoutInflater.Inflate(Resource.Layout.trans_layout, null);
view.FindViewById<TextView>(Resource.Id.supply_amount_txt).Text = item.amount1;
view.FindViewById<TextView>(Resource.Id.demand_amount_txt).Text = item.amount2;
//view.FindViewById<TextView>(Resource.Id.Text3).Text = item.client_code;
view.FindViewById<TextView>(Resource.Id.supply_cur_txt).Text = item.cur1;
view.FindViewById<TextView>(Resource.Id.demadn_cur_txt).Text = item.cur2;
view.FindViewById<TextView>(Resource.Id.rate_txt).Text = item.rate;
view.FindViewById<TextView>(Resource.Id.ID_txt).Text = item.tran_id;
view.FindViewById<TextView>(Resource.Id.user_name_txt).Text = item.username;
view.FindViewById<TextView>(Resource.Id.tran_date_time_txt).Text = item.tran_date ;
accept_btn = view.FindViewById<Button>(Resource.Id.btn);
amo2 = Convert.ToDecimal(item.amount2);
cu2 = item.cur2;
amo1 = Convert.ToDecimal(item.amount1);
cu1 = item.cur1;
rat = Convert.ToDecimal(item.rate);
tr_id = Convert.ToInt32(item.tran_id);
cl_code = item.client_code;
accept_btn.Click +=delegate {
myWS.ChekTranIDAsync(Convert.ToInt32(item.tran_id));
XTran = Convert.ToInt32(Convert.ToInt32(item.tran_id));
myWS.ChekTranIDCompleted += MyWS_ChekTranIDCompleted;
};
return view;
}
private void MyWS_ChekTranIDCompleted(object sender, myWS.ChekTranIDCompletedEventArgs e)
{
//myWS.accept_tranAsync("123", Convert.ToDecimal(item.amount2), item.cur2, Convert.ToDecimal(item.amount1), item.cur1, Convert.ToDecimal(item.rate), "ابو ليلى", Convert.ToInt32(item.tran_id), item.client_code);
myWS.accept_tranAsync("123", amo2, cu2, amo1, cu2, rat, "xxx", XTran, cl_code);
myWS.accept_tranCompleted += MyWS_accept_tranCompleted;
}
Upvotes: 0
Views: 170
Reputation: 9988
accept_btn.Click +=delegate
This code is executed multiple times as items are recycled for visual display and GetView gets run multiple times for the same view holder. So you need to unsubscribe first.
Upvotes: 0