Android Auto-select check box - android

Can some one tell me how can i auto select a check box when a function completes. I check a condition, After the function has completed i need to automatically view that check box is selected.
Thanks in Advance.

You can check the CheckBox automatically from xml
<CheckBox
android:id="#+id/checkbox1"
.
.
.
android:checked="true"
/>
or set java code like
CheckBox cbCheckbox = (CheckBox)findViewById(R.id.checkbox1);
cbCheckbox .setChecked(true);

Related

make Android Textview or EditText selectable

I want to make EditText or Textview selectable in my android project .
project is for android 4.0+ . I add this : txtView.setTextIsSelectable(true) and also : txtView.setCustomSelectionActionModeCallback(new myCallback());
to make my custom selection menu .
but this error happend when i want to select the text .
W/TextView﹕ TextView does not support text selection. Action mode cancelled.
i searched about the error but didn't find the solution .what should i do ?
<TextView
android:id="#+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textIsSelectable="true"
android:text="" />
*API Level 11 and up only
setTextIsSelectable does fix the problem on Android 7.1.1 for sure. The setEnabled(false) and then true didn't work.
editText.setTextIsSelectable(true);
My exact situation was having setFocusable(false) and adding an onClickListener, then setting setFocusable(true) and onClickListener(null) gave me the error in the OP.
(not correct syntax but you get the idea)

How to remove the button image of checkbox by java coding?

I know to remove the button image of checkbox in xml with following code:
<CheckBox
android:layout_width="wrap_content"
android:layout_height="25dp"
android:button="#null"
android:background="#drawable/notxtcheckboxbtn"
android:layout_weight="1"/>
But I need to add checkbox in my java code. And "newCheckBox.setButtonDrawable(null);" doesn't work!
Anybody know how to remove it in java code? Thanks in advance!!!
In the case that you just want the image to be transparent, you could try setting the image to android.R.color.transparent. That should get you the effect you're looking for.
Otherwise if you want to hide the button and disable it, you can use set visibility() and set it to gone or invisible.
Try:
android:button="#android:color/transparent"

Is it possible to make a checkbox/radio button uncheckable?

The program I am making has several views in which the user is trying to basically figure out a lot of boolean values. Sounds strange, but what I mean is that my device will connect to another device via bluetooth, and then read the status of that device. I basically display a checklist of the current status of that device. So depending on what that device is doing, different checkboxes are checked. Is there a way to make all of the checkboxes unselectable?
Even better, is there a way to hardcode this into the XML file?
Have you considered using android:clickable for an xml attribute for your checkboxes?
From the documentation:
Defines whether this view reacts to click events.
If it cannot react to click events, then it effectively becomes uncheckable.
<CheckBox
android:id="#+id/blahblah"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false" />
and in your code you can call cbox.setChecked(boolean)
to expand on what crocboy and nicholas.hauschild said.
Setting this in you XML
android:enabled="false"
will make the button/checkbox be grayed-out, to show it is disabled
Another way to do this is to set it to:
android:clickable="false"
Here is the code to make a RadioButton that is red, that turns green when checked (in your code), but can not be checked by the user.
android:checked="false"
android:textColor="#d1d2d4"
android:buttonTint="#d1202d"
android:textColorHighlight="#248d51"
android:clickable="false"
AND here is the code to check it (this is using JSON: so it is checking if english=="yes")
String yes = "yes";
if(yourObject.english.equals(yes)) {
if (m_english.isChecked()) {/*do nothing */}
else m_english.toggle();
}
Check this out: http://developer.android.com/reference/android/widget/CheckBox.html
You can use checkbox.setEnabled(false) to make it unselectable.
Try this in your XML: android:enabled="false"
It's supposedly deprecated, but may work depending on your traget SDK.
Hope that helps!

how to show that the radio button is selected permanently

i have the same problem as
how to show the radio button is selected is still ticked? but in android platform... can anybody help me please..
my codes are
<RadioButton
android:checked="false"
android:id="#+id/BBC"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ffff6600"
android:text="BBC NEWS"
android:typeface="serif"
android:textStyle="bold"
android:layout_x="10px"
android:layout_y="100px">
</RadioButton>
Thanks in advance...
You could save the value (when changed) to SharedPreferences, read it each time the page is loaded, and set the checked state based on that.
You can use a static variable like is_ticked & set its value true/false when user tick it. and check value of this variable in onCreate() if(is_ticked) set radio button to checked else unchecked .
A question with similar content was asked yesterday:
I have radio button for the user to choose if he/she wants to keep his/her account logged in.
you can't solve this problem just with the layout.xml - you need to save the status of the radio button and load it again once the appropriate activity is started
You could use this:
mListView.setItemChecked(selectedPosition, true);//this will check(enable) the desired radio button.
selectedPosition, you can save using SharedPreferences.

How can we custmize Check Box in Android?

I want to display Check box like Radio button though is it possible to give our own shape to the check box
if possible than help me please thanks
Yes. It is possible. Use this code
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:button="#android:drawable/btn_radio"/>
you need to set your own shape or image for both of it's state and have to handle it in the code....

Categories

Resources