android


Adding a checkbox in conextual action bar


Hello I am trying to add a check box to contextual action bar.
First idea was to set android:actionLayout it worked but I cannot to get if this checkbox was clicked
case R.id.action_select_all:
Toast.makeText(context,"Clicked",Toast.LENGTH_SHORT).show();
return true;
Second idea was to set icon in this way
<item
android:id="#+id/action_select_all"
android:orderInCategory="2"
android:title="Item"
android:icon="#drawable/check_box"
android:checkable="true"
app:showAsAction="always"/>
icon
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="#drawable/checked"></item>
<item android:state_checked="true" android:drawable="#drawable/checked"></item>
<item android:drawable="#drawable/uncheck"></item>
</selector>
I get Toast but Icon doesn't change. How should I do it. I found that setting a actionLayout should work but I cannot get the source
EDIT:
I'am trying something like this but it also doesn't work
<item
android:id="#+id/action_select_all"
android:actionLayout="#layout/my_checkbox"
android:orderInCategory="2"
android:title="Item"
android:checkable="true"
app:showAsAction="always" />
and action
#Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
CheckBox checkBox=(CheckBox) item.getActionView();
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Toast.makeText(context,"clicked",Toast.LENGTH_SHORT).show();
}
});
}
You should
<item
android:id="#+id/check_all"
android:checkable="true"
android:showAsAction="always"
android:icon="#android:drawable/ic_menu_preferences"
android:title="#string/action_check"/>``
And then in the Activity who inflates it you should have something like this in order to reflect the change of the checked state (otherwise it won't change the selected state even if you press it):
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case R.id.check_all:
item.setChecked(!item.isChecked());
return true;
}
}

Related Links

Web Worker for Android
Create 2 or more tables for one class in ORMLite
File format considerations: tree structure with text and binary data
Sending intent with bundle using console
Second maven repository in gradle on an Android Project
Custom view converting to bitmap returning black image
String to JsonObject returns null
Hide application icon when SearchView is open
How to increase the android action bar tabs text size
Android layout size in code
no resource identifier found for attribute 'layout_Below' in package 'android'…?
Sharing binary files in Android
Catch http response in Retrofit before passing it to the calling activity
Add data to database and retrieve dynamically in a textview
Electronic Data Collection in West Africa (with no internet / cell network)
Android Action Bar Title is not centered

Categories

HOME
cygwin
nunit
case
opendj
mips
telegram-bot
zip
jax-ws
retrofit2
special-characters
little-proxy
owin
octave
resultset
opengl-es-3.0
datastage
ipmitool
plink
glyphicons
atlassian-stash
microsoft-dynamics-nav
chargify
forgot-password
foreign-keys
jmp
squashfs
postscript
exit
scriptella
jboss6.x
ms-access-web-app
8051
ceylon
google-cast
sql-server-2000
simplecv
github3.py
installshield-le
hibernate-search
nested-lists
modalviewcontroller
getlasterror
openproject
connection-pool
p4merge
news
numberpicker
doc
watchface
signal-strength
dynamic-linq
ntvs
datamaps
remedy
trojan
arq
libjpeg
flac
juice-ui
testrail
donations
stripe-connect
cudd
simplepie
mediametadataretriever
project-organization
gcloud-ruby
upx
grass
concurrentmodification
dllimport
sony-lifelog-api
atoi
rdflib
dnssec
gamekit
showdialog
angular-gettext
rickshaw
formview
encryption-asymmetric
unix-socket
spring-remoting
vbe
cfcache
inputmismatchexception
printdialog
hidapi
cardreader
cascadingdropdown
chart-director
dopostback
lambdaj
mbeans
socketserver
ruby-1.8
squishit
application-verifier
nstokenfield
duplex
django-piston
product-management
soappy
leader

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App