When I click on button then I have invoked the buttonView.setSelected(true) method to set button in selected state, but first time button not selected and second time click button get selected. Code: main.xml
<Button
android:id="@+id/pauseButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/pause"
android:background="@drawable/item_selected" />
item_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:drawable="@drawable/btn_pause">
</item>
</selector>
Initialize Button
Button pauseBtn = (Button) findViewById(R.id.pauseButton);
Click code:
@Override
public void onClick(View v)
{
int viewID = v.getId();
if(viewID == R.id.pauseButton)
{
pauseBtn.setSelected(true);
}
}
I don't understand why button not selected on first click.