I'm new to android programming. I'm trying to change a item inside a layerlist when the user press a button. The problem is that when the button is clicked, the drawable disapears. If I finish the intend and start it again, the drawable apears updated. Can someone see what I'm doing wrong?
The XML code for the layerlist is:
- Code: Select all
<layer-list android:id="@+id/avatar_image" xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/bg_layer"
android:drawable="@drawable/background01" />
<item
android:id="@+id/skin_layer"
android:drawable="@drawable/skin01" />
<item
android:id="@+id/face_layer"
android:drawable="@drawable/face01" />
(...)
In the XML Code for the window I have:
- Code: Select all
<ImageView
android:id="@+id/avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/avatar_image"
android:layout_centerHorizontal="true"
/>
So for the OnClickListener I have:
- Code: Select all
layerView = (ImageView) findViewById(R.id.avatar);
layerList = (LayerDrawable) layerView.getDrawable();
- Code: Select all
bgButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
layerList.setDrawableByLayerId(R.id.bg_layer, res.getDrawable(R.drawable.background02));
layerList.invalidateSelf();
}
});
Without invalidateSelf() the behaviour is the same. Can someone help me out?

