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();
Related
Hello I have an application which I got entries by barcode scanner. I use Zebra TC56 as testing device.
I need to show a warning message to the user and that is why I have a custom dialog box.
Dialog box is being showed when user gets an error. Picture of my dialog box can be seen here :
Below red part is a button and when button is clicked , dialog box will be closed and user will turn the latest screen.
Everything works fine but there is somethin I dont want. When user scans a barcode(enters data) button is trigered and dialog box is closed.
I want dialog box to be closed only by clicking the button(TAMAM) from the screen. But when I scan anything, dialog box is closed.
Here is the code of the dialog box class :
public class ViewDialog {
public void showDialog(Activity activity, String msg){
final Dialog dialog = new Dialog(activity);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setCancelable(false);
dialog.setContentView(R.layout.customdialog);
TextView text = (TextView) dialog.findViewById(R.id.text_dialog);
text.setText(msg);
Button dialogButton = (Button) dialog.findViewById(R.id.btn_dialog);
dialogButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();
}
}
I tried to get focus to somewhere except the button(TAMAM) but it didnt help. If someone knows how to dismiss enter key from the barcode scanner, I really need some help and will be appreciated. (I already set the device to send Enter key because I need in other screens)
Few ways to do this that I can think of.
Firstly, I presume you are using DataWedge to automatically append the enter key to scanned data, you could dynamically switch to a profile which did not send the enter key but was identical in every other way using the SWITCH_PROFILE API: http://techdocs.zebra.com/datawedge/6-3/guide/api/switchtoprofile/. This is presuming that you still need to be able to scan when the dialog is visible, if you wish to disable scanning entirely you could use the SCANNER_INPUT_PLUGIN API: http://techdocs.zebra.com/datawedge/6-3/guide/api/scannerinputplugin/.
Secondly, you could use the EMDK profile API to change the parameters of the KeyStroke output plugin (http://techdocs.zebra.com/emdk-for-android/6-3/mx/data-capture/keystroke/#keystrokeoutput) then apply that newly modified profile. I've never tried that myself but it should work - check out the following sample for the principles behind that: http://techdocs.zebra.com/emdk-for-android/6-3/samples/data-capture/
Thirdly, you could use the Java SDK for the scanner which gives you more control over how the scanner behaves (http://techdocs.zebra.com/emdk-for-android/6-3/api/)
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.
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+
First, I will like to give a big Kudos to Stuart Lodge for this awesome framework. Together with Xamarin's Visual Studio integration, this is one of the most productive cross platform frameworks I have laid my hands on.
What I want to achieve is launch a dialog containing a selectable ListView when a button is clicked. I need access to the selected item when the user closes this dialog. Is there a recommended way to do this using the Mvvmcross' dialog plugin while following the MVVM paradigm?
I am using the following Activity to create a dialog.
[Activity(Theme = "#android:style/Theme.Holo.Dialog")]
public class SearchResultDialogView : MvxActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.SearchResultView);
}
}
Navigating to SearchResultDialogViewModel from another view model brings up this view as modal. So it looks like I am heading in the right direction. However, the dialog is missing the OK and Cancel buttons and I will also like to get rid of the default header. Think I need an AlertDialog but so far I have had no success launching one with this code:
[Activity(Theme = "#android:style/Theme.NoTitleBar")]
public class SearchResultDialogView : MvxActivity
{
protected override Dialog OnCreateDialog(int id, Bundle args)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.SetTitle("some title");
return builder.Create();
}
}
Apologies if this question is vague. I am new to Android UI development.
TIA.
There are several different uses of the word dialog here.
Android Dialogs are 'popup displays' and are covered in http://blog.ostebaronen.dk/2013/02/using-dialogs-in-mono-for-android.html
The MvvmCross Dialog plugin is a code-based form-builder forked from the existing MonoDroid.Dialog and MonoTouch.Dialog tools - see https://github.com/migueldeicaza/MonoTouch.Dialog
The Holo Dialog display is (actually I'm not sure) some theme-based skin on a normal Activity.
With these in mind...
If you want to display a general popup window to collect some data, then you can try using a fragment based dialog to collect data - this is demonstrated (with a little code behind) in Fragments HomeView.cs with NameDialogFragment.cs - for general background on fragments, watch N=26 in http://mvvmcross.wordpress.com/
If you want to use a separate activity for data collection, then #gschackles wrote this article on one way of returning data from child viewmodels - http://www.gregshackles.com/2012/11/returning-results-from-view-models-in-mvvmcross/ - I'm sure other schemes could also be used.
If you do want to learn about the Mvx Dialog plugin, see N=23 in http://mvvmcross.wordpress.com/
You can do it with the builder.
http://developer.android.com/guide/topics/ui/dialogs.html#AddingAList
The code is:
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
builder.setTitle(R.string.pick_color);
.setItems(R.array.colors_array, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// The 'which' argument contains the index position
// of the selected item
}
});
return builder.create();
}
and you can get your element by returning the which value to your caller.
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.