Hi Guys!
In this tutorial we are learning about the dialog fragment.
A fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
More detail about the dialog fragment visit the android developer site Dialog Fragment.
So lets start the coding about the alert dialog in Fragment.
You can download the source code Dialog Fragment
In this tutorial we are learning about the dialog fragment.
A fragment that displays a dialog window, floating on top of its activity's window. This fragment contains a Dialog object, which it displays as appropriate based on the fragment's state. Control of the dialog (deciding when to show, hide, dismiss it) should be done through the API here, not with direct calls on the dialog.
More detail about the dialog fragment visit the android developer site Dialog Fragment.
So lets start the coding about the alert dialog in Fragment.
main.xml
MyAlertDialog,java
package com.sunil.alert;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.widget.Toast;
public class MyAlertDialogWIndow extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
OnClickListener positiveClick = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity().getBaseContext(), "Application finishing ...", Toast.LENGTH_SHORT).show();
getActivity().finish();
}
};
OnClickListener negativeClick = new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(getActivity().getBaseContext(), "No option selecting", Toast.LENGTH_SHORT).show();
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage("Do you want Yes or No ?");
builder.setNegativeButton("No", negativeClick);
builder.setPositiveButton("Yes", positiveClick);
builder.setTitle("Confirmation");
Dialog dialog = builder.create();
return dialog;
}
}
MainActivity.java
package com.sunil.alert;
import com.sunil.alert.R;
import android.app.Activity;
import android.app.FragmentManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
public class MainActivity extends Activity implements OnClickListener{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button click = (Button) findViewById(R.id.btn_quit);
click.setOnClickListener(this);
}
@Override
public void onClick(View v) {
FragmentManager fm = getFragmentManager();
MyAlertDialogWIndow alert = new MyAlertDialogWIndow();
alert.show(fm, "Alert_Dialog");
}
}
You can download the source code Dialog Fragment
Update Contact :
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email : Fajarudinsidik@gmail.com
No Wa/Telepon (puat) : 085267792168
No Wa/Telepon (fajar) : 085369237896
Email: Fajarudinsidik@gmail.com
atau Kirimkan Private messanger melalui email dengan klik tombol order dibawah ini :