Question

Click:

lstText.ItemClick += (sender, args) =>
{
    Logon(GetString(Resource.String.LogonMessage), sUUID, sUserId, sUserPIN);
};

Alert Dialog:

private void Logon(string message, string sUUID, string sUserId, string sUserPIN) // 
    {
        RunOnUiThread(() =>
        {
            var uuidFetch = this.GetSystemService(Context.TelephonyService) as Android.Telephony.TelephonyManager;
            var IMEI = uuidFetch.DeviceId;

            var getUserId = LayoutInflater.From(this).Inflate(Resource.Layout.Login, null);
            getUserId.FindViewById<TextView>(Resource.Id.getUserId).Text = sUserId;

            var getPIN = LayoutInflater.From(this).Inflate(Resource.Layout.Login, null);
            getPIN.FindViewById<EditText>(Resource.Id.sUserPin).Text = sUserPIN;

            new AlertDialog.Builder(this)
            .SetTitle(GetString(Resource.String.LogonTitle))
            .SetMessage(message)
            .SetView(getUserId)
            .SetView(getPIN)
            .SetCancelable(true)
            .SetPositiveButton(GetString(Resource.String.LogonOk), (sender, e) =>
            {
                sUUID = IMEI;
                sUserId = "474";
                sUserPIN = getPIN.FindViewById<EditText>(Resource.Id.sUserPin).Text;
                Window.SetSoftInputMode(SoftInput.StateHidden);

                ThreadPool.QueueUserWorkItem(o => Authorize(sUUID, sUserId, sUserPIN));
                SetContentView(Resource.Layout.Splash);
            })
            .SetNegativeButton(GetString(Resource.String.LogonCancel), (sender, e) =>
            {
                Window.SetSoftInputMode(SoftInput.StateHidden);
            })
            .Show();
        });

As you can see in the alert dialog I have my sUserId static (since I'm testing and building the app and I'm really early in developement) but I need it to be a value from the list since every item (ergo user) in the listview has his own sUserId.

A few lines from my Item Adapter:

var sUserId = view.FindViewById<TextView>(Resource.Id.sUserId);
sUserId.Text = item.sUserId != null ? item.sUserId : "";

I will provide any further code/info if needed. Thank you for your time, your advice and any hints to help me solve my problem.

Was it helpful?

Solution

The argument of the ItemClick Event you are handling contains a lot of useful stuff, such as the position of the clicked item in the ListViews Adapter, but also the View and its contents.

So if you know the ListViewItem view contains a TextView you can in your ItemClick handler have code like follows, which extracts the content of it:

lstText.ItemClick += (sender, args) =>
{
    var userIdTextView = args.View.FindViewById<TextView>(Resource.Id.sUserId);
    var userId = userIdTextView.Text;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top