1

I have a button that I want to clear certain fields after it is pressed. I have a button event that is supposed to display a question before the clear functionality is implemented. After the user confirms they want to clear the button then the button will clear the text in the fields. However, as of now the dialog isn't displaying. Below is a sample of my Clear Button function. Please let me know if you see anything I am not seeing.

 void btnPalletClear_Click(object sender, EventArgs e) { dialog = new Dialog(this, Android.Resource.Style.ThemeHoloLightDialogNoActionBarMinWidth); View myView = View.Inflate(this, Resource.Layout.confirmation_dialog, null); myView.FindViewById<TextView>(Resource.Id.txtConfirmTitle).Text = "Clear Pallet"; myView.FindViewById<TextView>(Resource.Id.txtConfirmMessage).Text = "Are you sure?"; myView.FindViewById<LinearLayout>(Resource.Id.llQuantity).Visibility = ViewStates.Gone; myView.FindViewById<Button>(Resource.Id.cmdConfirmCancel).Click += delegate { dialog.Dismiss(); }; myView.FindViewById<Button>(Resource.Id.cmdConfirmOK).Click += delegate { dialog.SetContentView(myView); dialog.Show(); txtPalletUNQ.Text = ""; adapter.lstPallet.Clear(); adapter.NotifyDataSetChanged(); txtPalletVTPID.Text = ""; }; } 
6
  • 1
    Can you put a breakpoint inside the Resource.Id.cmdConfirmOK Click event and see if the delegate is getting triggered when you click the button? I think it may have to do with the fact that you're attaching a delegate within btnPalletClear_Click Commented Dec 18, 2018 at 17:11
  • 1
    Ok. I just did and it's not being triggered when inside the Resource.Id.cmdConfirmOk. Commented Dec 18, 2018 at 17:14
  • 1
    Yeah I think the trouble is from attaching an event while inside an event. Try doing like a public bool ClearClicked = false; at the class level, then when clear is clicked do ClearClicked = true. Then attach the cmdConfirmOK event from outside the btnPalletClear_Click method and inside cmdConfirmOK check if (ClearClicked) { ... do your stuff here ... then ClearClicked = false; } or something like that. Just guessing Commented Dec 18, 2018 at 17:25
  • 2
    I cut out the dialog.SetContentView(myview); , dialog.Show(); and pasted it outside of the cmdConfirmOk and it fixed it. Commented Dec 18, 2018 at 19:36
  • 2
    Uh, yeah, you were showing the dialog in the method that handles a click event from the dialog. Since you solved your own problem, add your solution as an answer and accept your own answer, so other don't stop here and look thinking it still needs a solution. thanks! Commented Dec 20, 2018 at 1:56

1 Answer 1

1

I cut the dialog.SetContentView(myview), and dialog.Show() out and pasted it in outside of the cmdConfirmOk and it fixed it.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.