Android Studio popup text - android

I new to Android Studio, still a lot to learn. I'm developing a engineering related app with several different activities, most do calculations and some have results that could be 15 or so lines.
I would like to have the results on a separate page, trying to keep screen clutter down. Does AS have anything like a popup text that I could output to, or would it be better to add another activity that is just a textlist or a table and output to that.
Thanks Steve.

Try AlertDialogs. They have a scrollbar so they can display long texts too.
But for 15 lines you might want a new activity.
A simple Example:
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setTitle("Title")
.setMessage("Message")
.setNegativeButton("Close", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
})
.create();
alertdialog.show();

Related

How to make a alert dialog button left and right instead of both align right without using custom view in android

Here is the general way I build an alert dialog. It is not crash just the outcome doesn't suit my expectation.
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setMessage(R.string.dialog_fire_missiles)
.setPositiveButton(R.string.fire, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
})
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// User cancelled the dialog
}
});
// Create the AlertDialog object and return it
builder.create().show();
Outcome:
But what I want is the cancel and fire button use up all the space of the dialog box rather than both align at the right side.
Just like the cancel and ok button. Ignore the check box what I need is only those button position.
Since I saw a lot of other app such as vine,twitter,foursquare etc display the alert dialog with the button which I desire so is there a way or method I can assign to the alert dialog while create it, I know there is a lot of way which can achieve this but I'm wondering is there a way without to use custom view or edit the LayoutParams of the button?
So recently I been talking to one of twitter developer what he said is every device have difference way to manage their user interface. Even there is a way better to use a custom dialog to make sure that on all device it is presenting the way what you want it to look like.
Final outcome use a custom dialog if you really want it to look like which way you want to.

Android AlertDialog.Builder displays blank unless a theme is supplied

I have recently begun work on an existing android app and noticed that one of the modals displays as a white blank square. I did some research and someone suggested that supplying a theme should fix it. I tried this and it does fix the issue but i don't understand why this was working without it and now its not. The code we use to initialize the AlertDialog looks like this
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setItems(R.array.media_resume_options, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//handle selection logic here
//......
}
});
builder.create().show();
I can fix it by changing the instantiation line to
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_DARK );
I don't see any changes to this part of the code that might have caused it. Could it be affected by something else? whats the potential risk that it might affect other dialogs?
It can't be blank,the textcolor and background color both are white that's why you think it is blank.
How to change default text color of dialogbox is explained here
Change dialog text color on 5.0+

Android Testing: how to click on dialog box's button?

Using Junit, I can click on “Set Time” button (as shown on the figure 1). Then it will open a new dialog box as shown in the Figure 2 (at the end). Can you please tell me how I can click the “Done” button on the newly opened dialog box? If you can show me an example, I would grately appreciate it.
In that case perhaps the best option is to use monkeyrunner of if you prefer to write your tests in Java you can use the chimpchat library. It use is described in Using monkey from Java.
if you use AlertDialog , you must use this method :
.setPositiveButton("Done",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
}
}) )
In API >= 15, callOnClick(), else performClick()
dialog.findViewById(android.R.id.button1).callOnClick();

Android - How to implement a listbox as a modal dialog/popup

In my Android app, when a user clicks on a button, I want a list box to show up as a modal dialog, just like the way a Spinner works, except that the list box can also allow multiple choices. I tried using ListView as described in the android hello-listview tutorial (http://developer.android.com/resources/tutorials/views/hello-listview.html). Unfortunately it doesn't seem to work the way I had expected it to. It doesn't show up as a modal dialog like the Spinner. I tried looking at what the Android browser does when a listbox is to be displayed. I browsed to www.functionx.com/html/lesson14.htm in the browser on my Android device and saw the following behavior (and this is exactly the behavior I want in my app):
When a dropdown/combobox in HTML is clicked, a spinner comes up as seen in the image here:
http://img842.imageshack.us/img842/803/htmlcombobox.png
When a single select listbox is clicked, again a spinner comes up as seen here:
http://img13.imageshack.us/img13/3355/listboxsingle.png
And when a multi-select listbox is clicked, a multi-select spinner / listview shows up in a dialog as seen here:
http://img835.imageshack.us/img835/711/listboxmulti.png
So my questions are:
What is this widget (in the last image above) that allows multi-select in a modal dialog. I'm sure this must be a component already available on the Android platform since it's being displayed in the browser.
Even the Spinners (in the first 2 images) in the browser look different than the default Spinner I'm seeing in my app. Would the browser be applying custom skinning / colors to the background and text of the Spinners that it displays?
Here's the code in case anyone's interested:
new AlertDialog.Builder(this)
.setMultiChoiceItems(R.array.select_dialog_items,
new boolean[]{false, true, false, true, false, false, false},
new DialogInterface.OnMultiChoiceClickListener() {
public void onClick(DialogInterface dialog, int whichButton,
boolean isChecked) {
/* User clicked on a check box do some stuff */
}
})
.setPositiveButton(R.string.alert_dialog_ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Yes so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked No so do some stuff */
}
})
.show();
Check the ApiDemos sample project, the AlertDialogSamples activity. There is a button labeled "Repeat alarm" that invokes a modal dialog with a multiple choice list.
In any case, a good place to start would be AlertDialog.Builder.

How to use vendor theme in Android application

I'm developing my "Hello, World" application for Android and came around something that annoys me.
The theme used for my app's AlertDialog isn't the same used for other such dialogs presented on the device. The device is a HTC Desire HD on which I've changed the theme, but I was expecting that standard UI elements (like AlertDialog) would somehow reflect the device theme. It's something that I'm missing or maybe a know problem with some vendors/models?
Here's my code:
final AlertDialog.Builder confirm = new AlertDialog.Builder(this);
confirm.setTitle("Delete")
.setMessage("Really Delete?")
.setPositiveButton("Delete", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
// ...
}
})
.setNegativeButton("Cancel", null)
.show();
And here's how the dialog looks like in different situations:
Device's AlertDialog with default theme (Messages app)
Device's AlertDialog with changed theme (Messages app)
My app's AlertDialog (with both default and changed theme)
Thanks.
Your assumption is correct.
HTC have most likley created customized dialogs for the HTC apps.

Categories

Resources