All AlertDialog in one file

alertdialogpractice.java package key.lab.alertdialogpractice; import java.nio.channels.AlreadyConnectedException; import android.app....

alertdialogpractice.java

package key.lab.alertdialogpractice;

import java.nio.channels.AlreadyConnectedException;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainPracticeActivity extends Activity {

Button onebtn, twobtn, threebtn, multichoicebtn, singlechoicebtn, listbtn;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_practice);

onebtn = (Button) findViewById(R.id.btnmessage);
twobtn = (Button) findViewById(R.id.btnTwoButton);
threebtn = (Button) findViewById(R.id.btnThreeButton);
multichoicebtn = (Button) findViewById(R.id.btnMultiChoice);
singlechoicebtn = (Button) findViewById(R.id.btnSingleChoice);
listbtn = (Button) findViewById(R.id.btnList);

onebtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog adOne = new AlertDialog.Builder(
MainPracticeActivity.this).create();

adOne.setTitle("Show Message");
adOne.setMessage("Here Is The Message");
adOne.setIcon(R.drawable.ic_launcher);
adOne.setButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(),
"you select ok ", Toast.LENGTH_SHORT).show();
}
});
adOne.show();
}
});

twobtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog adtwo = new AlertDialog.Builder(
MainPracticeActivity.this).create();

adtwo.setTitle("Delete");
adtwo.setMessage("Are you sure ??");
adtwo.setButton("Yes", new DialogInterface.OnClickListener() { //you can also use setPositiveButton() for YES
//and setNegativeButton() for NO
//it is use for lower android versions
//netural is used for the nothing setNeutralButton()
@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(),
"You clicked Yes", Toast.LENGTH_SHORT).show();
}
});

adtwo.setButton2("NO", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(),
"you selected NO ", Toast.LENGTH_SHORT).show();
}
});
adtwo.show();
}

});

threebtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog adthree = new AlertDialog.Builder(
MainPracticeActivity.this).create();

adthree.setTitle("Contact Us");
adthree.setButton("call",
new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog,
int which) {

Toast.makeText(getApplicationContext(),
"You selected CALL",
Toast.LENGTH_SHORT).show();
}
});

adthree.setButton2("Email", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(), "you selected Email ", Toast.LENGTH_SHORT).show();
}
});

adthree.setButton3("Text", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

Toast.makeText(getApplicationContext(), "you selected Text ", Toast.LENGTH_SHORT).show();
}
});
adthree.show();

}
});

multichoicebtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog admulti =new AlertDialog.Builder(MainPracticeActivity.this).setIcon(R.drawable.ic_launcher).setTitle("Select").setMultiChoiceItems(R.array.fruits,new boolean[]{true,true,false,false,false,true} ,new DialogInterface.OnMultiChoiceClickListener() {

@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {


}
} )

.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int pos) {

String fruit[]=getResources().getStringArray(R.array.fruits);
// Toast.makeText(getApplicationContext(), "you selecte the "+pos+","+fruit[pos], Toast.LENGTH_SHORT).show();
}
})

.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


}
}).show();


}
});


singlechoicebtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

AlertDialog adsingle =new AlertDialog.Builder(MainPracticeActivity.this).setTitle("Select Any One")
.setSingleChoiceItems(R.array.fruits, 3, new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


}
})

.setPositiveButton("OK", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


}
})

.setNegativeButton("Cancle", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {


}
})
.show();
}
});

listbtn.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

Dialog dialog=new Dialog(MainPracticeActivity.this);

dialog.setContentView(R.layout.dialog_call);
dialog.setTitle("Contact Us");

final EditText edit=(EditText)dialog.findViewById(R.id.etCall);
Button btcall=(Button)dialog.findViewById(R.id.btnCall);

btcall.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {

Intent intent=new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+edit.getText().toString()));
startActivity(intent);
}
});
}
});
}



@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_practice, menu);
return true;
}

}

acitvity_main_parctice.xml

<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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainPracticeActivity" >

    <Button
        android:id="@+id/btnmessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:text="Alert Message" />

    <Button
        android:id="@+id/btnTwoButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnmessage"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="23dp"
        android:text="Two Button Alert" />

    <Button
        android:id="@+id/btnThreeButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnTwoButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="21dp"
        android:text="Three Button Alert" />

    <Button
        android:id="@+id/btnMultiChoice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnThreeButton"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="MultiChoice Button" />

    <Button
        android:id="@+id/btnSingleChoice"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnMultiChoice"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="15dp"
        android:text="SingleChoice Button" />

    <Button
        android:id="@+id/btnList"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/btnSingleChoice"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="22dp"
        android:text="List Button" />

</RelativeLayout>

dialog_call.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <EditText
        android:id="@+id/etCall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:ems="10"
        android:hint="Enter Num"
        android:inputType="numberPassword" >

        <requestFocus />
    </EditText>

    <Button
        android:id="@+id/btnCall"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/etCall"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="44dp"
        android:text="Call" />

</RelativeLayout>

COMMENTS

Name

Alert Android Chat Expandable Expandable Listview Expandable Listview with Json Facebook GCM JSON Login Notification PDF SDK 4.0
false
ltr
item
Android Knowledge: All AlertDialog in one file
All AlertDialog in one file
Android Knowledge
http://androidknowledgeblog.blogspot.com/2015/03/all-alertdialog-in-one-file.html
http://androidknowledgeblog.blogspot.com/
http://androidknowledgeblog.blogspot.com/
http://androidknowledgeblog.blogspot.com/2015/03/all-alertdialog-in-one-file.html
true
2625512956379495182
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy