android


Android: Databinding expression with enum comparison


is it possible to create a databinding expression and control the visibility of a view element by using enumerations? What I want to achieve is the following
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="#{user.editType == EditType.EDIT_PROFIL ? View.VISIBLE : View.GONE}">
The EditType class is very simple
public enum EditType {
NONE,
EDIT_PROFIL,
EDIT_ADDRESSES; }
It would be awesome if I can use this enumeration within the XML to control the visibility of my LinearLayout.
Anybody got an idea how to achieve this?
To me it seems like what you want to achieve is possible and I dont see anything wrong except maybe u lack of the tag? I dont see it...
<data>
<import type="com.example.my.app.EditType"/>
</data>
You can do this is Java code, not is xml.
public enum EditType {
NONE,
EDIT_PROFIL,
EDIT_ADDRESSES; }
LinearLayout ll = (LinearLayout) findViewById(R.id.ll);
if(user.editType == EditType.EDIT_PROFIL){
ll.setVisibility(View.VISIBLE);
}else{
ll.setVisibility(View.GONE);
}
I would recommed you to separate the logic from the UI. All logic of the visibility should be done in java code in diferent events. I would say something like #Demo_Mail suggested would work if implemented on the OnCreate() method of your Activity/Fragment but reading the data-binding tag suggests me that you want to do this dynamically, at any point in the run (correct me if Im wrong). In that case I would suggest to create an OnClick() or OnSelectItem() method that will be executed in the moment the user selects a value of the enum (in a comboBox for example). This method will set the visibility of the view.

Related Links

Very Slow only with setVisibility in listview (desperate)
outgoing call answered in PhoneStateListener
How to get google access token after successfull login?
append more items to listfragment on scroll end
How to compress Ti.utils.base64encode and decompress using .Net method?
How to hide dependent Edittextpreferences when a Checkboxpreference is checked?
Do 'Chrome Apps for Mobile' use native web-view on each platform?
get background color from textview without using ColorDrawable (API 11)
how to disable status or notification bar for android activities
Is values-sw300dp working on lower versions of Android?
AndroId MediaPlayer error (1,-4) prepareAsync method
keep last 10 and delete all other rows - sqlite
Can i put the same package name and keyhashes in multiple facebook app?
ImageView shrinks when image is replaced with another image of same size
Connection between a phone and another phone [closed]
Calling method from AOSP

Categories

HOME
turing-machines
ns-3
character-encoding
flex
solaris
bitbucket-api
discrete-mathematics
qpython
google-chrome-app
windows-ce
xcodebuild
shared-libraries
flash-player
parameter-passing
coin3d
package.json
nodemcu
asp.net-core-webapi
rubymotion
squashfs
backpack-for-laravel
visual-studio-extensions
exit
easeljs
jboss6.x
draft-js-plugins
surveymonkey
bulletphysics
nstimer
google-cast
livelink
record
database-comparison
jmockit
erb
login-script
lubridate
salesforce-communities
google-knowledge-graph
zoomify
z-notation
bc
hackintosh
comparison-operators
stringtokenizer
lpsolve
bindingnavigator
apache-spark-dataset
monkey-testing
jide
magento-2.0.7
configurationmanager
pair-programming
headless
arules
reshape
mach-o
cmp
cronexpression
docpad
webjars
google-cloud-console
model-associations
observablecollection
riot
invoke-sqlcmd
cycle2
highland.js
boomerang
java-money
terracotta
batik
zscript
uncompress
dulwich
amiga
airbrake
fits
shopizer
openbabel
delayed-execution
showdialog
packet-sniffers
angular-gettext
sql-scripts
jama
grails-plugin-rabbitmq
jjaql
vsx
hibernate-entitymanager
ie8-compatibility-mode
breakout
dtmf
inappsettingskit
node-blade
idn
fragmenttransaction
rmiregistry
listitem
fusefabric
socketserver
uideviceorientation
delimited-text
vs-android
addchild
folding
cldc
great-circle

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