Thursday, 15 September 2011

java - Alert Dialog - how to implement Cancel and Okay button -


I have received this alert dialog in which there are two buttons (OK and cancel). I want to know how I know about implementing it.

So when you click the Cancel button, it should close the warning dialogue and return to the piece that I am currently in. And if I click on OK button then it should change the current warning dialogue and put it in another place.

This is under the consent for my code. Java file;

  public class confirmed DialogFragment {@Override public discourse onCreateDialog (bundled savedInstanceState) {extends last AlertDialog.Builder builder = new AlertDialog.Builder (getActivity ()); Layout Inflter INF = getActivity () GetLayoutInflater (); See last DIALAG = inf.inflate (R.layout.example_xml, null); Builder.setView (theDIalog); AlertDialog dialog = builder.scent (); theDIalog.findViewById (R.id.makeaTransferOk) .setOnClickListener (New View.OnClickListener () {@Override public void onClick (View v) {Toast.makeText (getActivity (), "OK button", Toast.LENGTH_SHORT) Show ();}}); theDIalog.findViewById (R.id.makeaTransferCancel) .setOnClickListener (New View.OnClickListener () {@Override public void onClick (View v) {dialog.dismiss ();}}); Return dialog; }}  

This is my code for example_xml;

  & lt ;? Xml version = "1.0" encoding = "utf-8" & gt; & Lt; RelativeLayout xmlns: android = "Http://schemaskandroidkcom/apk/res/android" android: orientation = "vertical" android: Layout_width = "Match_parent" Android: Layout_height = "Wrap_content" android: background = "# ffc0c0c0 "& Gt; & Lt; Button Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" Android: Cancel text = "or" android: id = "@ + id / makeaTransferCancel" / & gt; & Lt; Button Android: Layout_width = "Wrap_content" Android: Layout_height = "Wrap_content" android: text = "right" android: id = "@ + id / makeaTransferOk" / & gt; & Lt; / RelativeLayout & gt;  

Please someone can help me

Try the functionality that you have described above:

  AlertDialog.builder builder1 = New AlertDialog.Builder (reference); Builder1.setMessage ("Write your message here."); Builder1.setCancelable (true); Builder1.setPositiveButton ("OK", New DialogInterface.OnClickListener () {Click on Public Zero (DialogInterface Dialog, IND ID) / / put your code, when necessary that when right click is done then dialog .cancel ();}}); Builder1.setNegativeButton ("Cancel", New DialogInterface.OnClickListener () {public void onClick (DialogInterface dialog, int id) {dialog.cancel ();}}); Alert Demo Alert 11 = Builder 1.create (); Alert11.show ();  

No comments:

Post a Comment