android - Enable/disable EditText based on whether adapter has items -


i'm using data binding library. have in xml:

<edittext    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:enabled="@{!myadapter.isempty}"/> 

i want edittext enabled when spinner adapter not empty. when app starts, edittext disabled. far, good.

then, in activity, items inserted in adapter. after:

myadapter.notifydatasetchanged(); 

edittext not enabled. have more?

to have ability notify data binding use observableboolean this:

... <variable name="isadapterempty"           type="android.databinding.observableboolean" /> ... <edittext    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:enabled="@{!isadapterempty}"/> 

and notify databinding changes this:

myadapter.notifydatasetchanged(); isadapterempty.set(myadapter.isempty()); 

or can make own method inside adapter return observableboolean instead of simple boolean , provide ability manage value adapter.


Comments

Popular posts from this blog

python - How to insert QWidgets in the middle of a Layout? -

python - serve multiple gunicorn django instances under nginx ubuntu -

module - Prestashop displayPaymentReturn hook url -