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

set orientation portrait phonegap android
Android custum listview layout issue
Android JNI Using Pre built .so file in C Code
Open Activity with backwards to MainActivity in my app
Problems Adding TextView Programmatically Without Erasing Views in XML - Android
ndk-build: Header file of static prebuilt static library not found even on LOAD_STATIC_LIBRARY
Android studio. Module not specified after import
Android Java getId() name not int value [duplicate]
Ntlm code works on only Samsung devices
Webview - open links in external apps and browsers / android
alarm never triggers , as it should do android
Enabling GPS programmatically, causes the GPS indicator to flash while the GPS button is disabled
Android SQL lite table insert issue
Count Total Number of List Items in a ListView
Facebook Share Dialog in Android not showing content
Google anlytics is not working integrated in android app ,real time data is not showing

Categories

HOME
eslint
string
telegram
nunit
knitr
vsm
jquery-ui
angularfire2
webix
extjs4.2
arangodb
text-mining
tput
gkturnbasedmatch
selenium-ide
shared-libraries
mongodb-csharp
firefox-addon
google-data-studio
pyramid
bourbon
enterprise-miner
href
ios10.2
inno-download-plugin
scriptella
epsilon
gmock
beta
slidetoggle
amazon-quicksight
sinch
jaws
failover
twiml
event-flow
anki
python-2.6
cart
jmockit
dsx-desktop
reactjs.net
openerp-7
node-mssql
resolution
vmware-fusion
postgresql-8.4
install.packages
opencmis
opennms
magento-2.0.7
netbeans6.8
facebook-pixel
tf
mongotemplate
corruption
carrot2
ngmaterial
sundials
libjpeg
filenet
javafx-css
cudd
cubism.js
uiactionsheet
pushbots
themoviedb-api
pypiserver
xvim
google-books
wso2greg
ocra
ansi
teamcity-9.1
nsurlsessiondatatask
uvc
beatsmusic
punycode
formview
cuba
ora-00904
amslidemenu
embedded-fonts
node-blade
traceability
preload
patricia-trie
objectquery
oracle-enterprise-linux
window-decoration
predicatebuilder
flex-mobile
pinch
denied
fsevents
strsep
unattended-processing
photolibrary
folding
zend-rest
online-storage
wcf-proxy

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