按钮1-7(每行一个)正确地将数字1-7发送到编辑组件活动/屏幕(数字与按钮所在的行相对应,基于'位置')。但是,当我点击按钮8-10时,由于某种原因,它会将数字1-3发送到编辑组件活动/屏幕,而当我再次重试按钮1-3时,发送到编辑组件活动的数字都将不同步。
我不知道第1至7行的按钮如何发送正确的数字,但突然之间第8行及以上的按钮却没有发送正确的数字。
自定义listview适配器类
public override View GetView(int position, View convertView, ViewGroup parent)
{
View row = convertView;
//Row
if (row == null)
{
row = LayoutInflater.From(mContext).Inflate(Resource.Layout.listview_row, null, false);
}
//Set component details
TextView Category = row.FindViewById<TextView>(Resource.Id.txtViewCategory);
Category.Text = allComponents[position].CategoryName;
TextView Name = row.FindViewById<TextView>(Resource.Id.txtViewName);
Name.Text = allComponents[position].Name;
TextView Price = row.FindViewById<TextView>(Resource.Id.txtViewPrice);
Price.Text = allComponents[position].Price;
ImageButton editComponent = row.FindViewById<ImageButton>(Resource.Id.imgBtnEditComponent);
//Take the user to the edit screen for a given component
if (!editComponent.HasOnClickListeners)
{
editComponent.Click += (sender, e) =>
{
// Declare the activityas intent
var intent = new Intent(mContext, typeof(Edit_componentActivity));
//Store the row position
var rowPostion = (position + 1);
//Transfer the component's row to the edit screen
intent.PutExtra("edit_component_row_position", rowPostion);
//Start the activity of intent
mContext.StartActivity(intent);
};
}
return row;
}
编辑组件活动
// Create your application here
SetContentView(Resource.Layout.edit_component);
//Get the component's row position
var editComponentRowPosition = Intent.GetIntExtra("edit_component_row_position", 0);
Toast.MakeText(this, editComponentRowPosition.ToString(), ToastLength.Long).Show();
//Get the notes text view of the screen
TextView editName = FindViewById<TextView>(Resource.Id.txtEditEditComponentName);
//Assign the notes text view the component's notes
editName.Text = editComponentRowPosition.ToString();
以下是一些屏幕截图。
按钮1-7(每行一个)正确地将数字1-7发送到编辑组件活动/屏幕(数字与按钮所在的行相对应,基于'位置')。但是,当我点击...
我已在本地站点上复制了您的问题。原因是使用下面的代码为Button添加click不会受到控制。单击时,GetView
方法将继续调用此方法。不建议在Adapter中使用。