Android make a progressDialog ProgressBar Invisible - java

This is my ProgressDialog
progressBar = new ProgressDialog(Wallpapers.this);
progressBar.setCancelable(false);
progressBar.setMessage("Downloading " + downloadedFile + ".png");
progressBar.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressBar.setProgress(0);
progressBar.setMax(100);
progressBar.setButton(DialogInterface.BUTTON_NEGATIVE, "No", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
progressBar.setButton(DialogInterface.BUTTON_POSITIVE, "Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
progressBar.show();
Given that i can force the Buttons to become VISIBLE INVISIBLE GONE with the following:
progressBar.getButton(ProgressDialog.BUTTON_POSITIVE).setVisibility(View.INVISIBLE);
I had hoped to be able to do the same with the ProgressBar, this would allow more room for text to describe which button to press after the task is completed.
But the following is my best guess and its creating a NullPointer
progressBar.getButton(ProgressDialog.STYLE_HORIZONTAL).setVisibility(View.INVISIBLE);
Please note I am not looking to close the Dialog, only force the ProgressBar to be Invisible.
If it cannot be done then so be it, but any help would be great

ProgressDialog.STYLE_HORIZONTAL and ProgressDialog.STYLE_SPINNER are not Buttons, nor are they identifiers for Buttons in the AlertDialog class.
If you really want to stick with a ProgressDialog, you could hack your way around it by getting a View within the dialog (e.g. a Button or the View that has focus via getCurrentFocus()), then get the root View of the Dialog and traverse it's children until you find a ProgressBar. I wouldn't recommend this.
A better alternative would be to create your own layout that includes a ProgressDialog, and set that as an AlertDialog's View with setView(). This way you can define your own ID for the bar and retrieve it via the Dialog's findViewById() method.

Related

I want to create a popup

I'm trying to create a popup.
I would like to make the background of my popup transparent, and the border, because the popup is not filling the page, a bit more opaque, is there an easy way to do this?
I've tried with an activity but i can't get the effect i want, can you help me?
Something like this:
You can use Alert Dialogs for this and check this link for different uses
And a simple one like this
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Alert Dialog Title");
builder.setMessage("Your Message");
builder.setNegativeButton("No", null);
builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
}
});
builder.show();
result

How to create a popup with a scroll view programmatically?

I need to create a popup window programmatically, with a scrollview is this possible? i need to do everything in java side.
I was using a alert dialog but maybe is better a popup window, but didn't find much information on how to do it programatically.
i was using this code for the alert dialog
AlertDialog.Builder alert = new AlertDialog.Builder(OFActivityA.this);
alert.setTitle("Something");
alert.setText("fe");
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//what you need to do after click "OK"
}
});
alert.show();
i need to do everything in java side., not really - you can create your custom dialog with a custom layout and have any kind of layout that you would like to have.
For example, create dialogClass:
public class ProgressDialog extends Dialog {
public ProgressDialog(#NonNull Context context) {
super(context);
setContentView(R.layout.progress_dialog); //this is your layout for the dialog
}
}
And all you need to do to show your dialog is call those line:
ProgressDialog progressDialog = new ProgressDialog(getContext());
progressDialog.show(); // this line shows your dialog
You can put all your logic into the class using java as you want to only that now you can control your layout and how it looks in easier way.

Show AlertDialog without hiding ActionBar

I'd like to show an Alert Dialog which does not hide action bar. Is it possible to do it? The code which I tried is:
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setIcon(R.drawable.ic_launcher);
builder.setTitle("Basemap selection");
builder.setSingleChoiceItems(new String[]{"Create cache", "Use existing file"}, 0, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Some logic here.
}
});
builder.setNegativeButton(R.string.common_cancel, null);
builder.create().show();
It covers the whole screen but I need the action bar to be available while dialog is showing. I know that it might violate some android rules but UX department wants it.
The screenshot is:
If you want to make a non-modal dialog (allowing the user to tap outside the dialog and access the Action Bar while the dialog is visible), there's some information here that may be helpful: timed modeless dialog, specifically the use of dialog.getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL); - called after your dialog is visible.
The option is to change the activity to the Dialogue.Its simple process create an activity and goes to manifest file and set the theme of activity as
#android:style/Theme.DeviceDefault.Dialog

How to not check a checkbox when touch

I have a checkbox that is switching state on touch. I am wanting to find out how to ignore the state switch on touch. I have an onClickListener attached to the checkbox and inside of that I am changing the state with "Yes" or "No" buttons.
if(sog.isChecked()){
sog.setChecked(false);
} else {
sog.setChecked(true);
}
Edit: The checkbox is switching when touched and my yes button is also changing state.
Edit 2: I want my dialog to change the state rather than the checkbox doing it on it's own.
Edit 3:
sog.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
showDialog(3);
}
});
builder.setTitle("Checkbox")
.setMessage(
"Are you sure you want to switch checkbox?")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
if(sog.isChecked()){
sog.setChecked(false);
} else {
sog.setChecked(true);
setTotalTime();
}
}
})
.setNegativeButton("No",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
return alert;
I am just wanting to add a conformation on changing it from off/on.
Implement an OnCheckedChangeListener, registered on the CheckBox via setOnCheckedChangeListener(). In onCheckedChanged(), if the state of the CheckBox is one where you want additional confirmation, leave the CheckBox alone and pop your dialog. If the user taps a button in the dialog indicating that they do not want to make the change, then manually revert the checked state of the CheckBox to its prior value.
That being said, I agree with Waza_Be's comment. I am not a fan of "pop the confirmation dialog immediately" sorts of scenarios, though occasionally they are necessary. If there is some other sort of confirmation step as part of this UI (e.g., "save" action bar item), and you want to display a confirmation dialog at that point, that would be better, IMHO.

How to show a Progress Bar inside an AlertDialog Builder along with other elements without an XML?

I am trying to create an AlertDialog for a Bluetooth transfer after the transfer notification is touched in an android phone.
I am trying something like this:
Out of the below, I am getting everything - icon, title and two buttons. I am sure I can add other info like From, FileName and others using cursors with the help AlertDialog.Builder properties. I just do not know to get a progress-bar in it. I do not want to use an XML.
protected Dialog onCreateDialog(int id) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
alertDialogBuilder.setIcon(R.id.imageFile);
alertDialogBuilder.setTitle("File Transfer");
ProgressDialog progressDialog;
Context mContext = null;
progressDialog = new ProgressDialog(mContext);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//alertDialogBuilder.setView(progressDialog); //STUCK HERE
//"!" icon and "File Transfer"
//from : device name
//File: <name>
//Type: <type> (<size>)
//Receiving/Sending File
//<%> | Green progress bar
//Hide and Stop buttons
alertDialogBuilder.setPositiveButton("STOP", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialogBuilder.setNegativeButton("HIDE", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
return alertDialog;
}
I have everything in place except I am not able to figure out how to bring a progress-bar here.
Can I getjust a progress-bar using XML layout and use as
alertDialogBuilder.setView(R.id.what-ever-xml-file)
Or how to create a view for that progress-bar in he Java file itself and put a progressbar in that view and then put that view inside the dialog.
I want sth like this:
You can use Dialog and add ProgressBar on this by using
_dialog.addContentView(view, params) method.

Categories

Resources