android - setSelected(true) not working first time -


when click on button have invoked buttonview.setselected(true) method set button in selected state, first time button not selected , second time click button 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.

use

pausebtn.setpressed(true); 

read this blog


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -