Checkbox and radio buttons - android-xml

Do checkboxes have the permission to behave like radio buttons.I am developing a quiz application where in the options have the behaviour of radio buttons and the icon of the options are to be like the checkbox and is it possible for me to group the checkbox as we group radio buttons?

If you want Radio Buttons which look like Check boxes. Set Style of RadioButton as #android:style/Widget.CompoundButton.CheckBox
e.g:
<RadioButton style="#android:style/Widget.CompoundButton.CheckBox" />

I don't know if this is the best solution but you can create a "manager" for your checkboxes, and run it whenever any of them gets clicked.
For simplicity I've added the manager in the xml code, but feel free to use setOnClickListener, or setOnCheckedChangeListener as well.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox1"
android:onClick="cbgroupmanager"
/>
...
<CheckBox
android:id="#+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="CheckBox5"
android:onClick="cbgroupmanager"/>
</LinearLayout>
You need an ArrayList to iterate through, so you can settle the status of each checkbox, whenever any of them gets clicked on.
public class Q6910875 extends Activity
ArrayList<CheckBox> cb = new ArrayList<CheckBox>();
int CheckBoxNum = 5; //number of checkboxes
Iterator<CheckBox> itr ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
cb.add((CheckBox) findViewById(R.id.checkBox1));
cb.add((CheckBox) findViewById(R.id.checkBox2));
cb.add((CheckBox) findViewById(R.id.checkBox3));
cb.add((CheckBox) findViewById(R.id.checkBox4));
cb.add((CheckBox) findViewById(R.id.checkBox5));
itr = cb.iterator();
}
And here we have our manager, one iterator to pass trough the whole list, unchecking everything, when it reaches the clicked one, checks!
public void cbgroupmanager(View v) {
CheckBox cbaux;
while(itr.hasNext()) {
cbaux = (CheckBox) itr.next(); // we need this because it returns a Object, and we need the setChecked, which is a CheckBox method.
Log.d("soa", "click");
if (cbaux.equals(v)) //if its the one clicked, mark it as checked!
cbaux.setChecked(true);
else
cbaux.setChecked(false);
}
I also could find this other solution linked below, you can change the theme of your checkbox, but I dont have any experience on themes, so I can't help you any further on this approach.
Is it possible to change the radio button icon in an android radio button group

In radiabutton we can have the only one decision.But
checkbox we can have mulitiple options.
based on the usage we choose these controls.
for example,
RadioButton
Gender - o Male o Female
here we can select only one option
for example,
CheckBox
your Interested Games?
o cricket o football o valleyball o hockey

Related

Group of combobox dynamically in ZK

I am totally new in ZK. I need to create N combobox with their labels dynamically and populate them. I already populate a combobox with its id, but as there can be many combobox I should not know their ids, so It does not solve my problem.
I need to add N combobox, their labels and populate them dynamically. Is there any way to create that group of combobox and set them dynamically? Any ideas?
The code bellow works to populate the combo already knowing its fixed id.
//In this example I assume I have a label and a combobox. But could have 0 to N of them.
private Label lblComboMetadatos;
private Combobox cmbMetadatos;
//THEN
if (cmbMetadatos.getItemCount() == 0) {
lblComboMetadatos.setValue(trdMetaTipoDocumental.getNombreMetadato()); //Here I set the name of label but I should really can not know how many of them could be. There may exist 0..N
for (TrdMetadato trdMetaDato: trdMetaTipoDocumental.getTrdMetadatos()) {
String enumValores = trdMetaDato.getValoresEnumerado(); //Here I set the values of a combobox but I can not know how many of them could be. There may exist 0..N
cmbMetadatos.appendItem(enumValores]);
}
}
<zk>
<window id="idWindow" title="nameWindow" apply="controller.java" border="normal" closable="true" sizable="true" maximizable="true" maximized="true" height="85%" width="150%" style="overflow:auto;">
<!-- CONTINUES -->
<groupbox>
<hlayout>
<label id="lblComboMetadatos" />
<combobox id="cmbMetadatos"></combobox>
</hlayout>
</groupbox>
<!-- CONTINUES -->
</window>
</zk>
This question is very similar to your last question. You should wire the parent container (hlayout in this case) to your controller and then create the components there.
#Wire
private Component container; // your hlayout
#Override // This method should be specified by a composer super class
public void doAfterCompose(Component comp) throws Exception
for (<count an index or loop over data>) {
hlayout.appendChild(new Label("Hello World");
Combobox cb = new Combobox();
// append Comboitems
cb.addEventListener(Events.ON_SELECT, ...);
hlayout.appendChild(cb);
}
}
If you used MVVM, you could use children binding to create the components in zul.

Android Custom Keyboard Implementation

I am developing Android custom keyboard. I imported android.view.inputmethod.InputMethodSubtype in my code while doing this I am getting an error message like this imported one cannot be resolved. Is there any eclipse plugin I need to install, as per my knowledge Android version above 1.6 will support IMF.
The question is very old but I am answering it as it might help another user who sees this.
OP asked if there is any plugin for Eclipse to install to resolve the issue but now we have Android Studio.
For those who want to implement Android Custom Keyboard:
First, download Google sample project for Android Custom Keyboard to start with.
There are three important features to decide which one you want: 1) theme (custom layout), 2) subtype and 3) emoticons.
For themes/ layouts: Create layout files. See the example code below:
<com.domain.keyboard.android.LatinKeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/kb_bg_9"
android:keyBackground="#drawable/key_bg_fill_white"
android:keyPreviewLayout="#layout/key_preview_layout"
android:keyPreviewOffset="#dimen/keyPreviewOffset"
android:keyTextColor="#color/white"
android:popupLayout="#layout/keyboard_popup_layout" />
And use the following code in SoftKeyboard.java:
#Override
public View onCreateInputView() {
// Set custom theme to input view.
int themeLayout = sharedPreferences.getInt(THEME_KEY, R.layout.input_1);
mInputView = (LatinKeyboardView) getLayoutInflater().inflate(
themeLayout, null);
mInputView.setOnKeyboardActionListener(this);
// Close popup keyboard when screen is touched, if it's showing
mInputView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
mInputView.closing();
}
return false;
}
});
// Apply the selected keyboard to the input view.
setLatinKeyboard(getSelectedSubtype());
return mInputView;
}
For subtype: Create a copy of qwerty.xml and edit it to replace the keys. Create another instance of LatinKeyboard in SoftKeyboard.java and use if or switch logic.
private LatinKeyboard getSelectedSubtype() {
final InputMethodSubtype subtype = mInputMethodManager.getCurrentInputMethodSubtype();
String s = subtype.getLocale();
switch (s) {
case "ps_AF":
mActiveKeyboard = mPashtoKeyboard;
mCurKeyboard = mPashtoKeyboard;
break;
case "fa_AF":
mCurKeyboard = mFarsiKeyboard;
break;
default:
mCurKeyboard = mQwertyKeyboard;
}
return mCurKeyboard;
}
And edit methods.xml to add subtypes:
<input-method xmlns:android="http://schemas.android.com/apk/res/android"
android:settingsActivity="com.sunzala.afghankeyboard.android.ImePreferences"
android:supportsSwitchingToNextInputMethod="true">
<subtype
android:imeSubtypeLocale="en_US"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="ps_AF"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
<subtype
android:imeSubtypeLocale="fa_AF"
android:imeSubtypeMode="keyboard"
android:label="#string/label_subtype_generic" />
</input-method>
For emoticons: Find library and integrate it with a keyboard. The emoticons will display with a key press.
if (primaryCode == -10000) {
showEmoticons();
}
Where -10000 is keycode.

Monodroid tabs view

After implementing the Tabs Widget Sample I tried to play with it and add the third tab only after changing to the second tab
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.Main);
TabHost.TabSpec spec;
spec = TabHost.NewTabSpec("tab_test1").SetIndicator("TAB 1").SetContent(Resource.Id.textview1);
TabHost.AddTab(spec);
spec = TabHost.NewTabSpec("tab_test2").SetIndicator("TAB 2").SetContent(Resource.Id.textview2);
TabHost.AddTab(spec);
//spec = TabHost.NewTabSpec("tab_test3").SetIndicator("TAB 3").SetContent(Resource.Id.widget0);
//TabHost.AddTab(spec);
TabHost.TabChanged += new EventHandler<Android.Widget.TabHost.TabChangeEventArgs>(TabHost_TabChanged);
TabHost.CurrentTab = 0;
}
void TabHost_TabChanged(object sender, TabHost.TabChangeEventArgs e)
{
if (TabHost.TabWidget.TabCount < 3)
{
TabHost.TabSpec spec;
spec = TabHost.NewTabSpec("tab_test3").SetIndicator("TAB 3").SetContent(Resource.Id.widget0);
TabHost.AddTab(spec);
}
}
The problem is that I see the 3rd view overlay-ed on the first view before clicking the tabs, even though the 3rd tab appears only after clicking the 2nd tab. What's going on?
I'm guessing it's because the Third tab doesn't have tab to go to (since we don't create a TabSpec) so it just displays it directly on the screen.
You could set the content you want to display when the third tab is visible to invisible shown in the example below;
<TextView
android:visibility="invisible"
android:id="#+id/textview3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="this is a third tab" />
and then when the tab is displayed, the text view is made visible again.
Hope this helps,
ChrisNTR

OpenXML - Limiting the number of buttons showed in the group in custom MS-Word ribbon

I want to limit the number of buttons in the group of a ribbon in Word 2007 as the buttons are getting generated on the basis of data in the database. See the pic below. . I wanted to have limited number, say 6 or so in the ribbon with a dialogboxlauncher which when clicked will open a pane showing all the buttons. Is there any way of doing the same. Can somebody also tell me how to create that pane when somebody clicks on the dialogbox launcher?
The way I did it is to load some (say 6) of the items in the ribbon as buttons and add all the items as the CustomXMlPart in the document. In the document, I added a user control which contained a listbox. On the ribbon load, I get all the items from the CustomXmlPart and put them in the listbox. On the dialogbox launcher button click, I show/hide the user control to show all the items in the list.
Following are the steps in detail :-
a) Get all the items from the database and keep that in collection.
b) Generate the ribbon XML like the following withe the 6 buttons from the above collection :-
<?xml version="1.0" encoding="utf-8"?>
<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="RibbonLoad">
<ribbon>
<tabs>
<tab id="tabMyTab" label="MyTab">
<group id="grpItems" label="My items">
<button id="test1" label="test1"/>
<button id="test2" label="test2"/>
<button id="test3" label="test3"/>
<button id="test4" label="test4"/>
<button id="test5" label="test5"/>
<button id="test6" label="test6"/>
<dialogBoxLauncher>
<button id="btnShowAllItems" label="Show all custom tags" onAction="ShowAllItems" />
</dialogBoxLauncher>
</group>
</tab>
</tabs>
</ribbon>
</customUI>
c) Add the collection as the CustomXMLPart to the document :-
static void AddCustomTableXmlPart(WordprocessingDocument document)
{
MainDocumentPart mainDocumentPart = document.MainDocumentPart;
XDocument customTagsXml = GetAllItemsAsCustomXML();
if (mainDocumentPart.GetPartsCountOfType<CustomXmlPart>() > 0)
mainDocumentPart.DeleteParts<CustomXmlPart>(mainDocumentPart.CustomXmlParts);
//Add a new customXML part and then add content
var customXmlPart = mainDocumentPart.AddCustomXmlPart(CustomXmlPartType.CustomXml);
//copy the XML into the new part...
using (var ts = new StreamWriter(customXmlPart.GetStream()))
{
ts.Write(customTagsXml.ToString());
ts.Flush();
}
}
d) Go to the developer tab of your docm file, add a UserForm to the project and add a listbox to it. Write a subroutine which would load the items from the CustomXMlPart added already to the document and add those items to the listbox in the userform. Something like below :-
Sub LoadItems()
Dim totalItemsCount As Integer
totalItemsCount = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes.Count
Dim item As String
For i = 1 To totalItemsCount
item = ActiveDocument.CustomXMLParts(ActiveDocument.CustomXMLParts.Count).SelectNodes("//Items")(1).ChildNodes(i).text
' I had to remove the spaced before adding it as It was throwing errors
item = Replace(item, " ", Empty)
If Len(item) > 1 Then
ItemUserControl.lstItems.AddItem pvargItem:item
End If
Next i
End Sub
e) Define the sub named RibbonLoad which is called from the onLoad event of the ribbon (check the RibbonXML). Call the LoadItems sub from this RibbonLoad sub.
Sub RibbonLoad(ribbon As IRibbonUI)
LoadItems
End Sub
f) Define the following sub which will show/hide the user control. This is called on the onAction of the dialogBoxLauncher button. (see the RibbonXML)
Sub ShowAllItemss(control As IRibbonControl)
If ItemsUserControl.Visible = False Then
If ItemsUserControl.lstItems.ListCount = 0 Then
LoadCustomTags
End If
ItemsUserControl.Show
Else
ItemsUserControl.Hide
End If
End Sub

Radio items in GNOME panel applet's context menu

Is there a way to put radio menu items in a GNOME panel applet's context menu, and then control which of the items is marked as active? The official documentation is less than helpful, and all of the applets installed on my computer use normal menu items, so I can't look at their source code for any guidance.
In the XML file defining the context menu, for each radio <menuitem> set type="radio" and the group property to the name of the radio item group, like this:
<Root>
<popups>
<popup name="button3">
<menuitem name="Foo" verb="DoFoo" label="Foo is awesome" type="radio" group="mygroup"/>
<menuitem name="Bar" verb="DoBar" label="Bar is cool" type="radio" group="mygroup"/>
<menuitem name="Baz" verb="DoBaz" label="Baz rocks" type="radio" group="mygroup"/>
</popup>
</popups>
</Root>
You don't set up handlers to respond to the items being selected the same way you would for normal menu items. Instead, you listen for the "ui-event" signal on the BonoboUIComponent for the menu:
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
g_signal_connect (component, "ui-event", G_CALLBACK (popup_component_ui_event_cb), NULL);
/* ... */
static void
popup_component_ui_event_cb (BonoboUIComponent *component,
const gchar *path,
Bonobo_UIComponent_EventType type,
const gchar *state_string,
gpointer data)
{
}
path will be the full path (see below) of the item that was clicked. state_string will be the new state value of the item (see below). There will be two events for each click of a radio item: one to deselect the old item, and one to select the new one.
To manipulate the checked state of the buttons, use bonobo_ui_component_set_prop to set the "state" property to "0" (unchecked) or "1" (checked). To be safe, explicitly uncheck the old value; there are some corner cases where you could otherwise wind up with multiple radio items in the same group checked (particularly if the context menu hasn't yet actually been drawn).
BonoboUIComponent *component = panel_applet_get_popup_component (applet);
bonobo_ui_component_set_prop (component, "/commands/Foo", "state", "1", NULL);
bonobo_ui_component_set_prop (component, "/commands/Bar", "state", "0", NULL);
bonobo_ui_component_set_prop (component, "/commands/Baz", "state", "0", NULL);
Note that you identify the radio item by "/commands/name", where name is the name you gave the item in the XML file.
You could likewise use bonobo_ui_component_get_prop to look for which radio item is checked, but you're better off using the event handlers to detect when the user clicks on one.
In general, the documentation for BonoboUIComponent in libbonoboui should provide more information about ways to manipulate items in the menu.