I’m building an app framework for Android tablets, and I am running into a strange issue with some ImageButtons. These buttons (Next & Prev) are used to help navigate through “content pages” as part of the framework, and are using custom background drawables.
The issue is that whenever I click on the Prev button, the Next button highlights while the the Prev button does not. At first I thought it was a simple linking or @+id/ issue, but the Prev button’s action is performed, not the Next button’s.
Here is some relevant code:
In onCreate() method:
nextButton = (ImageButton) findViewById(R.id.nextButton);
prevButton = (ImageButton) findViewById(R.id.prevButton);
nextButton.setOnClickListener(this);
prevButton.setOnClickListener(this);
onClick method:
public void onClick(View v) {
if(_cpp == null){
finish();
}else if (v == nextButton) {
if (!_cpp.nextRes.equalsIgnoreCase("")) {
// load next page
_tempRes = _cpp.nextRes;
//start transition out animations
fadePageOut();
} else {
finish();
}
} else if (v == prevButton) {
if (!_cpp.prevRes.equalsIgnoreCase("")) {
// load previous page
_tempRes = _cpp.prevRes;
//start transition out animations
fadePageOut();
}
}
}
My drawable XML:
<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable= "@drawable/prev_arrowhigh" />
<item android:state_pressed="true" android:state_enabled="true"
android:drawable="@drawable/prev_arrowhigh" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/prev_arrow" />
<item android:state_enabled="true" android:drawable="@drawable/prev_arrow" />
</selector>
I’ve been debugging and searching for answer for two days now, with no luck. The funny thing is it used to work just fine… but even reverting to a previous version of my project didn’t seem to help at all.
Has anyone encountered this issue before or have any idea what could possibly be the cause of this?
Solved! stupid, stupid me…
Next button was displaying as selected because in my code (part not posted) disables the button during my fadePageOut() method (see posted code). The state-drawable was simply using the wrong images for enabled/disabled states.
This:
Should have been:
two days wasted because of a incorrect image…
*sigh*