Xamarin/C# Select only one Radio Button from custom list view

HkncoreHkncore ATMember ✭✭

Im using Xamarin to create my App. I have a custom ListView atm. with Radiobuttons in it. These Radiobuttons are clickable, but every single one of them is (multiple).

The result that I want should work like the following: Only 1 can be checked at the time. There are some Java solutions, but they don´t help me at all. Thanks in advance.

This is how I create my Listview

    mListView = FindViewById<Android.Widget.ListView> (Resource.Id.listView1);

    mItems = new List<Artikel>();
    mItems.Add(new Artikel() { Name = "X", Amount = 50 });
    mItems.Add(new Artikel() { Name = "Y", Amount = 300 });
    mItems.Add(new Artikel() { Name = "Z", Amount = 80 });
    mItems.Add(new Artikel() { Name = "A", Amount = 174 });

    MyListViewAdapter adapter = new MyListViewAdapter(this, mItems);
    mListView.Adapter = adapter;

Artikel.cs

class Artikel
{
 public string Name { get; set; }
 public int Amount { get; set; }
}

MyListViewAdapter.cs

private List<Artikel> mItems;
private Context mContext;


public MyListViewAdapter(Context context, List<Artikel> items)
{
    mItems = items;
    mContext = context;
}

public override int Count
{
    get { return mItems.Count; }
}

public override long GetItemId(int position)
{
    return position;
}

public override Artikel this[int position]
{
    get { return mItems[position]; }
}

public override View GetView(int position, View convertView, ViewGroup parent)
{
    View row = convertView;
    if (row == null)
    {
        row = LayoutInflater.From(mContext).Inflate(Resource.Layout.listview_row, null, false);
    }
    TextView txtName = row.FindViewById<TextView>(Resource.Id.Name);
    txtName.Text = mItems[position].Name;

    TextView txtamount = row.FindViewById<TextView>(Resource.Id.Amount);
    txtamount.Text = mItems[position].Amount.ToString();


    return row;  
}

Thanks in advance!

Sign In or Register to comment.