c# - onCreateDrawableState Never Called -


all,

i've got viewgroup subclass overrides oncreatedrawablestate() (xamarin.android in c# forgive pascal casing).

my override of oncreatedrawablestate() never gets called, however. i've tried calling refreshdrawablestate(), drawablestatechanged(). requestlayout(), , invalidate().

nothing seems work. method:

/// <summary> /// handles create drawable state event adding in additional states needed. /// </summary> /// <param name="extraspace">extra space.</param> protected override int[] oncreatedrawablestate (int extraspace) {     int[] drawablestate = base.oncreatedrawablestate(extraspace + 3);      if (completed)     {         int[] completedstate = new int[] { resource.attribute.completed };         mergedrawablestates(drawablestate, completedstate);     }      if (required)     {         int[] requiredstate = new int[] { resource.attribute.required };         mergedrawablestates(drawablestate, requiredstate);     }      if (valid)     {         int[] validstate = new int[] { resource.attribute.valid };         mergedrawablestates(drawablestate, validstate);     }      android.util.log.debug("row_view", "oncreatedrawablestate called");      return drawablestate; } 

i assume it'll work ok - never gets called. viewgroup nested in listview and/or linearlayout nothing seems help.

this related question has no answers work me.

edit: (i edited previous answer incorrect answer assumed implementing checkable interface)

oncreatedrawablestate seems propagated leaf nodes it's parent nodes (viewgroups) if child element (leaf) declares android:duplicateparentstate instance in textview. understand refreshdrawablestate goes down leaves , oncreatedrawablestate leaves if android:duplicateparentstate="true" set, haven't done thorough analysis though, interested in pointers documentation.

the following layout item in listview cause oncreatedrawablestate on mylinearlayout called:

<com.example.android.mylinearlayout xmlns:android="http://schemas.android.com/apk/res/android"    ...>         <textview         ...         android:duplicateparentstate="true"/>     </com.example.android.mylinearlayout> 

this won't:

<com.example.android.mylinearlayout xmlns:android="http://schemas.android.com/apk/res/android"    ...>         <textview         ...         android:duplicateparentstate="false"/>     </com.example.android.mylinearlayout> 

neither (the linearlayout won't propagate up):

<com.example.android.mylinearlayout xmlns:android="http://schemas.android.com/apk/res/android"    ...>         <linearlayout          ...         android:duplicateparentstate="false">         <textview             ...             android:duplicateparentstate="true"/>         </linearlayout> </com.example.android.mylinearlayout> 

this again will:

<com.example.android.mylinearlayout xmlns:android="http://schemas.android.com/apk/res/android"    ...>         <linearlayout          ...         android:duplicateparentstate="true">         <textview             ...             android:duplicateparentstate="true"/>         </linearlayout> </com.example.android.mylinearlayout> 

note there seems amalgam implementation of checkable interface.

the checkable interface can implemented views immediate children in listview, gridview etc. there no need have implemented further down view tree.

in case listview when in choice mode call setchecked on checkable interface:

http://androidxref.com/4.3_r2.1/xref/frameworks/base/core/java/android/widget/listview.java#1899

if (mchoicemode != choice_mode_none && mcheckstates != null) {             if (child instanceof checkable) {                 ((checkable) child).setchecked(mcheckstates.get(position));             }  

the implementation of checkable adds drawable state overriding oncreatedrawablestate. see other post example of this: mvxlistview checkable list item


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -