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.
Related
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
So I'm trying to get my application to show an editable text-field in a dialog. Once you've entered your desired text, you can hit 'OK' to use that text to go to the next view and do something based on that text.
So this is what my code looks like.
public void onClick(View v){
final EditText input = new EditText(MainActivity.this);
final AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("New Query");
alertDialog.setView(input);
alertDialog.setPositiveButton("Fire Query!", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton){
TableView.putExtra("query", input.getText());
startActivity(TableView);
}
});
alertDialog.show();
}
However, the compiler is telling me that it can't resolve setPositiveButton() and in fact when I look look in the code-complete box, it indeed does not show even though it is listed for the builder on the Android documentation
Any ideas? I should mention that everything but the setPositiveButton is working. I just can't do anything with a dialog with a title and an editText field.
You are not calling it on the builder. Move the create() call to later on (and change the type to the Builder).
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
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.
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.