Cómo configurar el icono de la estrella favorita en ON cuando se hace clic y en OFF cuando otra vez se hace clic en android

Android Mi actividad que tiene lista de citas es la siguiente.

package bank.quotes.famous; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.CheckBox; public class QuotesActivity extends FamousQuotesActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.quoteslayout); CheckBox favButton = (CheckBox)findViewById( R.id.favbutton ); 

He intentado agregar tu código aquí sin éxito. Mi xml es como abajo,>

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="856dp" android:background="@android:color/white" android:orientation="vertical" > <TableRow android:id="@+id/TableRow03" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.25" > <RelativeLayout android:id="@+id/RelativeLayout08" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/forquotesgrey" > <TextView android:id="@+id/TextView22" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/albertquote" android:textAppearance="?android:attr/textAppearanceMedium" /> <TextView android:id="@+id/TextView21" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="@string/alberteinstein" android:textAppearance="?android:attr/textAppearanceMedium" /> <CheckBox android:id="@+id/favbutton" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@+id/TextView21" android:layout_alignParentRight="true" /> </RelativeLayout> </TableRow> <TableRow android:id="@+id/TableRow06" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="0.25" > <RelativeLayout android:id="@+id/RelativeLayout10" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/forquotesgrey" > <TextView android:id="@+id/TextView16" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentTop="true" android:text="@string/stevequote" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@android:color/black" /> <TextView android:id="@+id/TextView15" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_alignParentRight="true" android:text="@string/stevejob" android:textAppearance="?android:attr/textAppearanceMedium" android:textColor="@android:color/black" /> <CheckBox android:id="@+id/CheckBox01" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentRight="true" android:layout_centerVertical="true" /> </RelativeLayout> </TableRow> 

Si a un usuario le gusta una cotización, debe ir a la actividad Favorita. También el botón fav debe brillar siempre si es favorito del usuario. Así es como funciona el botón favorito, ¿no? Esta es mi primera vez que añada un botón favorito así que tengo menos idea de hacerlo. Si pudieras ayudarme, realmente apreciaría eso. Gracias.

Si desea utilizar elementos estirados con estado, le resultará más fácil ocultar un ToggleButton o CheckBox que un ImageButton.

 <CheckBox android:id="@+id/star" style="?android:attr/starStyle" android:layout_width="wrap_content" android:layout_height="wrap_content" /> 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.