0

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.

Paradox Code
  • 148
  • 2
  • 14

1 Answers1

1

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;
}
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
  • Thank you Cheesebaron. Did help me a bit, though I'm still lost on how to actually use userId once the dialog starts? sorry for newbie questions but I just started out right with dev on C# (haven't really been learning it per say - discovering it as I go, learning by example :) ) – Paradox Code Jan 08 '13 at 10:54
  • 1
    I kind of assumed you knew what to do with the user ID! However after the `var userId...` line you can do whatever you want with it, just like in your first code example, you could call the `Logon` method. – Cheesebaron Jan 08 '13 at 16:37
  • Ok I had a minor case of stupit yesterday ;D sUserId = fetchUserId; before the logon method... no need for the textfield as well :) Thank you for all the help! – Paradox Code Jan 09 '13 at 06:36