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

Titanium Alloy crash on android, Cannot call method 'open' of undefined
Native components, armeabi-v7a, and thumb?
Checkbox getting deselected in arrayadapter in listview
Android: member variable becoming null
How to detect color of the center of camera streaming in android without OpenCV
Missing App Icon after modifying Manifest
Save Image from res/drawable to Image Gallery Android
SQL lite select for actual week (from monday till sunday)
how to get imageview height and width after pinch zoom?
How to properly create a customized animated drawable?
Android Backstack Management
how to get mobile number from my current Phone? it's display blank Mobile Number in Log. but when run on emulator its display emulator Number [duplicate]
Is it possible to have different label name of launcher activity & application name
script popup for android and iOS - for your device exist app, how?
Android border on a button difference between 4.4 and 4.0.3
Programmatically how to create Video in android

Categories

HOME
sonarqube
algorithm
search
oracle12c
webdriver
twig
jmx
swt
switch-statement
rds
bookmarks
jax-ws
trac
barcode
okhttp
mql5
dkim
mel
jxl
automatic-ref-counting
renjin
flatpak
parameter-passing
screen-readers
html5-appcache
mapstruct
swagger-2.0
solrcloud
articulate-storyline
rubymotion
squashfs
named-entity-recognition
ember-cli
joptionpane
event-store
expressionengine3
data.stackexchange.com
custom-post-type
shared
nstimer
intersystems-cache
winexe
datastax-enterprise-graph
comparable
uitapgesturerecognizer
google-earth
autodesk-designautomation
livelink
turfjs
clickjacking
instantiation
keras-layer
pop3
nested-lists
python-import
jwplayer6
sql-delete
servicestack-text
protege4
apic
google-data-api
apriori
httr
servermanager
x-ray
semantic-logging
yii2-user
opengl-4
skin
mouseleave
d3-force-directed
shinobi
vcloud-director-rest-api
cudd
builtins
ziparchive
latin
envi
vulcanize
neon
embedding
ellucian-scribe
beanstalk
flock
rdflib
google-refine
cakephp-2.7
phpldapadmin
uncaught-typeerror
viewer
sip-server
kissfft
ora-00904
reflector
winginx
alternate
scriptaculous
ebay-lms
kogrid
nebula
route-provider
kaleidoscope
traceability
stacky
http-status-code-410
qtconcurrent
uimanageddocument
saleslogix
inkcanvas
predicatebuilder
role
strsep
silent
duplex
strtod
mathematical-notation
unmanagedresources
soappy
httpcookie
cardspace

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