Is there a way to customize the buttons for Dialog?
Dialog confirm has two buttons (yes/no), but I would like to change the value of the buttons to something else other than (yes/no).
I have been looking for ways to do this, but the given Dialog methods are very limited in terms of having customizable buttons.
Try this:
Dialog choose: 'What is your choice?'
labels: #('Red' 'Black')
values: #(#red #black)
default: #red
I don't currently have access to a VisualWorks environment, but I seem to recall something along the lines of Dialog#choose:from:values: where you can pass in the dialog text, any button texts and the associated values, respectively. (There may be a few more arguments as well.)
Just browse the Dialog class (and its hierarchy) and you should be able to find such methods.
If no such method exists, it should be fairly easy to roll your own. It's Smalltalk, after all.
Related
Where exactly are 1) dialog 'text', 2) dialog 'OK' button, and 3) dialog 'Cancel' button defined or inherited from in CodenameOne?
Where can I see the code which instructs a dialog to be made of those components? Can someone direct me to the base class, method, etc. where each of those 3 items are defined?
I am referring to a Dialog meaning com.codename1.ui.Dialog.
Thanks
I suggest asking "how to do something" rather than "where something exists" as the answer to the latter might lead you to the wrong place.
E.g. in this case these things don't exist. All the static show methods in the Dialog eventually call into this uber method:
https://github.com/codenameone/CodenameOne/blob/master/CodenameOne/src/com/codename1/ui/Dialog.java#L904-L940
You will notice that it constructs the components dynamically to create the dialog and doesn't provide the means to manipulate said components as the Dialog is static methods are meant to be very simple stateless tools.
In my Android project I've already created a custom dialog: A class named SelectColorDialog, extending Dialog, that allows the user to view a large matrix of color cells in order to select a particular color. The dialog returns the selected color value (as Integer) to the dialog initiator – typically an Activity – via a callback function.
I've a similar custom dialog, SelectTypefaceDialog, to allow easy font selection. A list of available typefaces are shown, as ListView rows, each identified by name and with an associated short sample text rendered in that typeface. The available typefaces include usual droid fonts, such as NORMAL, MONOSPACE, etc. as well as any externally sourced TTF font files that the user cares to load into a particular subdirectory on the SDCard.
These custom dialogs were not initially designed to be used directly in conjunction with SharedPreferences, preferences definition XML files or with any PreferenceActivity. Instead of, each dialog can be popped up from any activity, via the user pressing a button or via a menu item. The activity classes that create these dialogs also have internal callback classes, selection event listeners, to detect when the user selects a color or font.
These two dialogs do not have OK and Cancel buttons. Instead, the user just clicks on an item - a view of some kind - in the dialog to select the corresponding color or typeface value (implicit OK) or else presses the device’s back button to dismiss the dialog with no action taken (implicit Cancel).
I would now like to go further and incorporate these two custom dialogs into the shared preferences framework via a preferences.XML and an associated PreferenceActivity.
I would prefer to base two DialogPreference subclasses directly on these existing dialogs if possible, but I cannot see how to do so. I suspect that I cannot, and that I'll need to start all over again, and copy or adapt all the java code that is presently in the custom dialog classes – for color or font display and selection – directly into the custom DialogPreference classes instead, perhaps by overriding onCreateDialogView() and/or other methods?
This question may be a bit old, but I hope to help those, looking at the same problem in future: just extend Preference instead of DialogPreference. DialogPreference is designed badly and expected "official" way to use custom Dialog - overriding protected showDialog method does not work, because this single method contains half of class logic.
I'm looking for a configurable modal dialog to popup over the top when a cell is clicked in a UITableView with various actions, some of which require input, some don't. Is Monotouch.dialog appropriate or is there a better way to achieve this?
The behaviour I'm looking for with the dialog (activated in the UITable) is the following:
- Fixed actions. Click a button, do something.
- Text input. Enter text (for example, reset a password), do something.
Alternatively, is it possible to use a custom controller such as QuickDialog https://github.com/escoz/QuickDialog?
Sincerely,
Adam
Popover for user-input is quite a common task. I would recommend UIPopoverController with custom views inside that when presented allow the user to complete an action / task / input. Quick dialog is a rendition of MonoTouch.Dialog ported to obj-C. You can use straight-up MonoTouch.Dialog if you like: https://github.com/migueldeicaza/MonoTouch.Dialog
I would also recommend my managed C# implementation of UIPopover for MonoTouch here (with video): https://github.com/anujb/Devnos.Popover
Video: http://screencast.com/t/lGwsvtEot9V
In my program I want the user to be able to choose between some options so I was using wxChoice component. Unfortunately after user interaction (clicking a button) I have to show custom text (not from my predefined list). Everything works fine if I use wxCombobox control but the drawback of this approach is that each time user selects an element from a list, selected text is highlited. It is annoying. I want the component to be read-only like. How to achieve this ?
Some code to visualize my question:
wxComboBox* viewAngle = wxDynamicCast( owner->FindWindow
( ID_CHOICE_3D_VIEWANGLE ), wxComboBox );
viewAngle->SetSelection( wxNOT_FOUND );
viewAngle->SetValue(_("Custom View"));
EDIT:
This control is used to set camera view in 3D object viewer application. Possible options are like: top, left, right, etc. It is also possible that the user moves 3D object using mouse. In that case I want my combobox to display "custom view" string. However "custom view" should not be a part of combobox list because selecting this option does nothing.
wxWidgets default implementation alwasy marks selected text. Which might be misleading for the user because he might think that he is expected to input any text.
IMHO, the custom text should be added to the wxComboBox control, the program could just ignore it when user selects that option.
Also, the wxComboBox's wxCB_READONLY style could be used to avoid the highlighting thing.
I want to design one form that contains TextField and ListView in J2ME. But I don't know how to create this form. It is looked like Dictionary Form. Could anybody help me to do that?
You can't really do that with the basic UI controls in MIDP.
List can't contain TextField.
I would suggest looking at LWUIT since it has better controls.
Otherwise, if you don't need to display Images in your List, then you can use a Form containing both TextField and StringItem. Unfortunately, an ItemStateListener added to the Form will probably not give you as much information as a List.
Implementing the list yourself in a CustomItem means writing quite a bit of code but is doable.
If what you need is a TextField where you enter a search String and a List that displays the search result, I suggest using a TextBox first, then a List. Separate screens are by far the quickest solution here.
Edit: you can't use swing in j2me. what you can do is have just a textfield in a form, then add/remove StringItems to/from the Form when the user changes the content of the TextField. You should be able to rely on ItemStateListener to tell you when the textfield content changes.