I’ve one menu button and a motion class for a longer state_pressed state (0,5 sec.). So long all works fine, but one problem occurs :
I’ve to press first time on my button, state_pressed doesn’t work at this first time then on the second attempt my code works correctly and state_pressed works with 0,5 seconds duration.
How can I make it that it works on the first press? I think tehre is a problem with the hover.xml file and in combination with the setBackgroundDrawable?
Thanks all in advance for ur help!
This is my hover.XML drawable
<?xml version="1.0" encoding="utf-8"?>
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/buttonstyle_pressed" />
<item android:drawable="@drawable/buttonstyle" />
And this is my java code
Button menubutton_start;
menubutton_start = (Button) FindViewById(R.id.menustart);
menubutton_start.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
menubutton_start.setBackgroundDrawable(getResources().getDrawable(R.drawable.hover));
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
Intent myIntent = new Intent(GameActivity.this, NextActivity.class);
GameActivity.this.startActivity(myIntent);
}
}, 500); // end of Handler new Runnable()
} // end of OnClick()
}); // end of setOnClickListener
The pressed state will happen automatically if you apply that style to the button.
You shouldn’t have to manually set the pressed state in your code at all.