Android Dialog Box Example...
Open xml file and below code:
Now open java file and paste below code
}
We can use maximum three buttons in dialog box by default and builder is used to create dialog box. Sequence of the buttons to appear on box: positive, neutral than negative.
Open xml file and below code:
<RelativeLayout xmlns:android="http://schemas. android.com/apk/res/android"
xmlns:tools="http://schemas. android.com/tools"
android:layout_width="match_ parent"
android:layout_height="match_ parent">
<Button
android:id="@+id/button1"
android:layout_width="wrap_ content"
android:layout_height="wrap_ content"
android:layout_alignParentLeft ="true"
android:layout_alignParentTop= "true"
android:layout_marginLeft=" 24dp"
android:layout_marginTop=" 17dp"
android:text="CLOSE"
android:onClick="close" />
</RelativeLayout>Now open java file and paste below code
package selecom.alert;
import
android.os.Bundle;
import
android.app.Activity;
import
android.app.AlertDialog;
import
android.app.AlertDialog. Builder;
import
android.app.Dialog;
import
android.content. DialogInterface;
import
android.view.View;
import
android.widget.Toast;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle
savedInstanceState) {
super.onCreate( savedInstanceState);
setContentView(R.layout.activi ty_main);
}
public void close(View v)
{
onCreateDialog(10);
}
protected Dialog
onCreateDialog(int id)
{
switch(id)
{
case 10:
Builder
builder=new
AlertDialog.Builder(this);
builder.setMessage("Activity will close!!!");
builder.setTitle("Warning..." );
builder.setIcon(R.drawable.warning_image);
//button
builder.setNegativeButton(" No", new DialogInterface. OnClickListener() {
@Override
public void
onClick(DialogInterface dialog, int which)
{
Toast.makeText( getApplicationContext(),
"Nothing happened", Toast.LENGTH_LONG).show();
}
});
//button
builder.setPositiveButton(" yes", new DialogInterface. OnClickListener() {
@Override
public void
onClick(DialogInterface dialog, int which)
{
finish();
}
});
//button
builder.setNeutralButton(" Thinking", new
DialogInterface. OnClickListener() {
@Override
public void
onClick(DialogInterface dialog, int which)
{
Toast.makeText( getApplicationContext(),
"i have to think", Toast.LENGTH_LONG).show();
}
});
AlertDialog
dialog=builder.create();
dialog.show();
}
return super.onCreateDialog(id);
}
We can use maximum three buttons in dialog box by default and builder is used to create dialog box. Sequence of the buttons to appear on box: positive, neutral than negative.
How to link a range,say 25- 30 from a radio button, to next page. The next page should display as "normal value". For 35-40, it should display "good value".
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteCoooooooooooooooool
ReplyDeleteI used Dialog box for the first time and it was awesome. Thanks
ReplyDeleteI don't know anything.
ReplyDelete