0

I have a alert dialog box in my code and I want to assign a value to a variable as the cancel button is pressed for that dialog.

My actual code is -

private void clicked() { AlertDialog.Builder builder = new AlertDialog.Builder(Feedback.this); builder.setTitle("FEEDBACK"); builder.setSingleChoiceItems(options, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub switch (which) { case 0: String url = "http://killmathsapp.blogspot.in/"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); break; case 1: Intent s = new Intent(Intent.ACTION_SEND); s.setType("plain/text"); s.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "[email protected]" }); s.putExtra(android.content.Intent.EXTRA_SUBJECT, "feedback from app"); startActivity(s); break; } } }); AlertDialog alert = builder.create(); alert.setCancelable(true); alert.show(); } 

3 Answers 3

1

very simple way for alert message in dialog box...

 public void onClick(View v) { if(somthing_wrong) { Dialog d=new Dialog(AmitregistrationActivity.this); d.setContentView(R.layout.detail); d.setTitle("Warning...."); d.show(); } else{ //Code that you want to execute } } 

also you have to create an detail.xml file like this

<ImageView android:id="@+id/imageView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:src="@drawable/detail" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginLeft="26dp" android:layout_marginTop="15dp" android:layout_toRightOf="@+id/imageView1" android:text="Please fill all Details..." android:textSize="20dp"/> 
Sign up to request clarification or add additional context in comments.

Comments

0
AlertDialog.Builder alert=new AlertDialog.Builder(this); alert.setTitle("FeedBack"); alert.setNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub dialog.dismiss(); //do Set variable here or any other code } }); alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { //do Set variable here or any other code } }).show(); 

2 Comments

i did by using alert.setOnCancelListener(new DialogInterface.OnCancelListener() { public void onCancel(DialogInterface dialog) { // TODO Auto-generated method stub click=0; } });
Its ok anything will work.I thought giving this type would help for other related dialoge handling.
0

This code is what you need. Just insert it wherever you need to launch the alert dialog. I haven't figured out how to launch the keyboard automatically , but it shouldn't be difficult.

AlertDialog.Builder alert = new AlertDialog.Builder(this); alert.setTitle(multiLangTranslation(R.string.manualshippermessage)); final EditText input = new EditText(this); input.setInputType(InputType.TYPE_CLASS_NUMBER); input.setRawInputType(Configuration.KEYBOARD_12KEY); alert.setView(input); alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Put actions for OK button here } }); alert.setNegativeButton(multiLangTranslation(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { //Put actions for CANCEL button here, or leave in blank } }); alert.show(); 

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.