Place icon at right of title in a AlertDialog builder - java

All the answers and info that i find at internet seems old and deprecated, i could add a simple icon at my title bar at left (user image), but i need to have 2 more images, a message and a phone at the right, like a simple user details view, the problem is that i don't know how to set the position of those images, the only thing i could do was this:
AlertDialog.Builder builder = new AlertDialog.Builder(Friends.this);
final User user = usersList.get(position);
builder.setTitle(user.getUsername());
builder.setMessage("You wanna delete friendgroup: " + user.getUsername());
builder.setIcon(R.drawable.ic_user);
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//myRef.child("Users").child(userId).child("FriendLists").child(friend.getName()).removeValue();
//friendList.remove(friend);
//mAdapter.notifyDataSetChanged();
}
});
builder.show();
with the builder.setIcon i could add a image at the left, but how can i add more icons and at the right of my title ? do i really need a custom builder to do this?
Thanks

You have to make a custom AlertDialog.
Try this:
Design a RelativeLayout that contains your icon, title and right message and phone icon and other things.
Set this layout to your AlertDialog using setView() method.
AlertDialog.Builder builder = new AlertDialog.Builder(Friends.this);
final User user = usersList.get(position);
LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.your_dialog_layout, null);
builder.setView(dialogView);
builder.setCancelable(false);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//myRef.child("Users").child(userId).child("FriendLists").child(friend.getName()).removeValue();
//friendList.remove(friend);
//mAdapter.notifyDataSetChanged();
}
});
builder.show();
Here is a good tutorial
Hope this will help~

Related

How to change the color of buttons in Alert Dialog? [duplicate]

This question already has answers here:
How can I change default dialog button text color in android 5
(18 answers)
Closed 4 years ago.
i am working in a social app and while the user wants to edit their feeds i want to give them a pop up alert dialog from where the user can edit their post. I tried the following code but the result that gave was not good
i want to change the color and want a better design .. what can be done for this
private void EditCurrentPost(String description)
{
AlertDialog.Builder builder = new AlertDialog.Builder(ClickPostActivity.this);
builder.setTitle("Edit post");
final EditText inputField = new EditText(ClickPostActivity.this);
inputField.setText(description);
builder.setView(inputField);
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
ClickPostRef.child("description").setValue(inputField.getText().toString());
Toast.makeText(ClickPostActivity.this,"Post Updated",Toast.LENGTH_SHORT).show();
}
});
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
Dialog dialog = builder.create();
dialog.show();
dialog.getWindow().setBackgroundDrawableResource(android.R.color.holo_purple);
}
There is a very simple way to make dialog with custom layout: Please review the code below:
final Dialog dialog = new Dialog(MainActivity.this);
dialog.setContentView(R.layout.dialog_news_description);//Your custom layout
TextView sometextview = dialog.findViewById(R.id.textView);// Textview in your custom layout
Button somebutton = dialog.findViewById(R.id.button_done);// Button in your layout
somebutton.setOnClickListener(new View.OnClickListener() {//on button click listener
#Override
public void onClick(View view) {
//DO your job....
//then...
dialog.dismiss();//dismiss the dialog
}
});
dialog.show();
You cannot change the default AlertDialog layout but you can inflate a custom layout to it. To start with you can check this post http://android-coding.blogspot.com/2011/07/create-custom-dialog-using.html

How to use a dialogue box within a popup window?

I have a popup window that gets executed when a button is pressed. When the user clicks "home" within the popup window I want a dialogue message to pop up asking the user if they are sure they want to quit.
Here is how I declare the popup window:
LayoutInflater inflater = (LayoutInflater) endlessflags.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout = inflater.inflate(R.layout.success_menu, (ViewGroup) findViewById(R.id.myPop5));
pwindo4 = new PopupWindow(layout, ActionBar.LayoutParams.MATCH_PARENT, ActionBar.LayoutParams.MATCH_PARENT);
pwindo4.setAnimationStyle(R.style.AnimationPopup);
pwindo4.showAtLocation(layout, Gravity.TOP | Gravity.CENTER, 0, 0);
And then I have a onTouchListener for the button that are also called in the popup window. I try to call the dialogue function I created but when I do nothing happens and I get no errors or crashes:
AlertDialog.Builder myAlert = new AlertDialog.Builder(mainActivity.this);
myAlert.setMessage("Would you like to quit?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
saveState = true;
saveState();
//finish();
dialog.cancel();
}
}).setNegativeButton("No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
saveState = false;
dialog.cancel();
}
});
My question is why is it that when I call the dialogue event function nothing seems to happen and how can I fix this so the dialogue box shows up when I click a button within my popup window?
You need to show the dialog:
AlertDialog dialog = myAlert.create();
dialog.show();

Android : Multiple Dialogs (or multiple dialog views)

In my app I need multiple dialogs or multiple views which will be updated after clicking positive and negative dialog buttons.
How should it looks in example:
1) Call first Dialog1
2) Inside Dialog1 I have some data and 2 buttons (positive and negative) onClick possitive Button I go to next Dialog2 on negative I exit dialogs.
3) Inside Dialog2 similar situation click on possitive button provides me to next dialog or dialog view but negative button leeds back to Dialog1
for now my code looks like :
public class DialogChoiceActivity extends DialogFragment {
LayoutInflater inflater;
View v;
public Dialog onCreateDialog(Bundle savedInstanceState) {
inflater = getActivity().getLayoutInflater();
v = inflater.inflate(R.layout.dialog_email,null);
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final Dialog dialog2 = builder.create();
builder.setTitle("Email " + " 1/10");
builder.setView(v).setPositiveButton("NEXT", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
}).setNegativeButton("Exit", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
}
});
return builder.create();
}
First of all I'm not sure which way is better create multiple dialogs or one Dialog with multiple Views. Which way is better if I want easily move from one dialog to another (or view). There are some problems because I cant update builder object or dissmiss it so how shold all this looks like ? what is best way to do that
Sorry for chaotic and weak language.
Create DialogFragment as you needed.
Make clicking on the positiveButton to show next dialog and dismiss current dialog.
From next dialog, clicking on negativeButton to show previous dialog and dismiss current one.

How to display popup option of "set as wallpaper" when user press on image for 3-5 sec in inageviewer app?

Following... this link ..How to set image as wall paper in viewpager app?. I am able to set wallpaper directly located in my drawable folder. However, i want to give user a chance to set wallpaper by displaying pop up dialogue box which should be displayed. When user clicks on images for 3-5 sec.
I am kind of new to android programming.. So, please help..
android framework already supporting class "alertDialogue.builder". you can set message whatever you wanna show in addition to dialogue buttons, title etc.
http://developer.android.com/reference/android/app/AlertDialog.Builder.html
5sec is too long to stay in one fingerpoint. in onsimplegesturedetector class, there is already "long press" detector
http://developer.android.com/reference/android/view/GestureDetector.SimpleOnGestureListener.html
you can set your own ontouchListener that implements onTouchListener that has gesture detector, detects long press and can show dialogue .
there can be better way but I'm using this logic in my project so you can reference and fix it if you find better way
findViewById("your wall paper image id").onTouchListener(new MyOnTouchListener());
class MyOnTouchListener implements onTouchListener{
GestureDetector gd = new GestureDetector(new SimpleOnGestureListener(){
#Override
public void onLongPress(MotionEvent e) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setTitle("Your Title");
alertDialogBuilder
.setMessage("click yes to set wallpaper!")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
//setting wallpaper
}
})
.setNegativeButton("No",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
dialog.cancel();
}
});
// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();
// show it
alertDialog.show();
}
});
}

In Android how to set image in DialogBox?

I created a dialogBox in my Android application.i want to show with image in that dialog Box.But i Cannot create image.kindly help me.
Thanks in Advance
here my Coding;
public void createbtnteam_adelaide()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setMessage("What kind of Banner do you Want to Create?");
//my new code
ImageView image = (ImageView) alertDialog.findViewById(R.drawable.team_brisbane);
image.setImageResource(R.drawable.team_brisbane);
alertDialog.setButton("Text Only", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setButton2("Text+Image", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.show();
}
}
i have Small icon in team_gwsid(imageid).
The Android Developer site has an excellent article on how to create dialogs in Android, including custom dialogs. I think you solve your problem by having a look at that, it's pretty easy to do.
Here's the link: http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog
By the way (not related to this question): I see you've asked six questions here on StackOverflow, and haven't accepted any of them. This is usually what you do when someone helps you to solve your problems.
There ia a alertDialog.setView(View view) method that enables you to set a custom view.
This does not affect the buttons or the titlebar.
In standard dialog the icon is shown only if you set title too. You have to use setTitle to see result of setIcon. Icon is shown in title of the dialog.
You can use Set icon or SetTitle to Display the Images in DialogBox. Read this Tutorial
public void createbtnteam_adelaide()
{
AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setIcon(R.drawable.team_adelaide);
alertDialog.setTitle("What kind of Banner do you Want to Create?");
alertDialog.setButton("Text Only", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.setButton2("Text+Image", new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog, int which) {
// here you can add functions
}
});
alertDialog.show();
}

Categories