关注代码:
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
List<string> numbers = new List<string>();
for (int i = 0; i < 10; i++)
{
numbers.Add((i + 1).ToString());
}
view = inflater.Inflate(Resource.Layout.fragment_1, container, false);
gridView = (GridView)view.FindViewById(Resource.Id.grid_1);
gridView.ChoiceMode = ChoiceMode.Single;
//Here event click item
gridView.ItemClick += (sender, e) =>
{
gridView.SetBackgroundColor(Color.ParseColor("#FFC107"));
};
ArrayAdapter<string> adapter = new ArrayAdapter<string>(Activity, Resource.Layout.item_1, numbers);
gridView.Adapter = adapter;
return view;
}
当我点击1项时,它正在绘制整个gridview。如何仅在点击的位置进行绘制?
关注图片:
当您点击数字5时,会发生这种情况:
我希望你只画5个。任何解决方案?
答案 0 :(得分:2)
在GridView
项目点击中,AdapterView.ItemClickEventArgs
包含被触摸的View
:
gridView.ItemClick += (sender, e) =>
{
e.View.SetBackgroundColor(Color.Red);
};