Forum Xamarin.Android


The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

List view of spinners - how to know which one is seleted

MarkGrahamMarkGraham USMember ✭✭
edited June 2017 in Xamarin.Android

I have a ListView of spinners that form a grid to input data as follows:

The listview corresponds to a list of type PenaltyItem.

    public class MultiColumnListViewAdapter : BaseAdapter<PenaltyItem>

public class PenaltyItem
    private const string TIME = "15:00";

    public string Date { get; set; }
    public string Game { get; set; }
    public string Quarter { get; set; }
    public string Time { get; set; }
    public string Player { get; set; }
    public string Penalty { get; set; }
    public string Yards { get; set; }
    public string Squad { get; set; }
    public string Result { get; set; }

    public PenaltyItem(Activity activity, List<PenaltyItem> penalties)
        Date    = DateTime.Now.ToShortDateString();
        Game    = SetGame(activity);
        Quarter = SetQuarter(activity, penalties);
        Time    = SetTime(activity, penalties);
        Player  = SetPlayer(activity);
        Penalty = SetPenalty(activity);
        Yards   = SetYards(activity);
        Squad   = SetSquad(activity);
        Result  = SetResult(activity);

When I click on Row A, Column Penalty I want to transfer the selection back into the ListView at the appropriate item.
Current all the spinners in column Penalty have the same id.
All the spinners in a particular column shared the same id.
So how to I know that a change in column Penalty is from Row A, B, C, D or E?

Should I give all the spinners a unique id?

I currently add all seven spinners per row at the beginning of GetView,

public override View GetView(int position, View convertView, ViewGroup parent)
        View row = convertView;

        if (row == null)
            row = LayoutInflater.From(_context).Inflate(Resource.Layout.listview_row, null, false);


I am open to a redesign.


  • MizanurRahman.0834MizanurRahman.0834 USMember ✭✭

    Do you have any unique Id fr each ListView item? If you have, you can easily get the Selected Item and then the Spinner from the Selected Item. Otherwise you can set Index for each item.

    public override View GetView(int position, View convertView, ViewGroup parent)
    var item = items[position];

            if (convertView == null)
                convertView = context.LayoutInflater.Inflate(Resource.Layout.GenericLVRow, null);
            convertView.FindViewById<TextView>(Resource.Id.txtDetail).Text = item.ToString();
            ImageView btnDelete = convertView.FindViewById<ImageView>(Resource.Id.btnDelete);
       **// Item position as index, That will help you to get the Unique Item from the ListView
            convertView.FindViewById<TextView>(Resource.Id.txtIndex).Text = position.ToString();**
            var btnEdit = convertView.FindViewById<ImageView>(Resource.Id.btnEditItem);
            btnEdit.Click += BtnEdit_Click;     // You can set the event in required Spinner
            return convertView;

    When you will select Spinner Item, It will return the selected Item position as follows:

    private void BtnEdit_Click(object sender, EventArgs e)
    switch (flag)
    case "A":
    View adviceRow = ((ImageView)sender).Parent as View;
    TextView txtAdviceIndex = adviceRow.FindViewById(Resource.Id.txtIndex);

    // Get the selected Item Position and get your required Spinner and Move forward
    int advicePosition = Convert.ToInt32(txtAdviceIndex.Text);

    case "P":

    Hope, It will help you!!!

  • MarkGrahamMarkGraham USMember ✭✭

    Do you have any unique Id for each ListView item?
    Otherwise you can set Index for each item.
    How do I set an index for each spinner?
    And then how do I retrieve/set data for each indexed spinner?

  • beginnerootbeginneroot USMember

    I am new in Xamarin, how to publish from remote sql database items and make possible to select it?

Sign In or Register to comment.