I've been working on this app for a while, and had zero issue with android:onClick's linking up with the relevant method in the activity.
...Then I started messing with themes and my CheckBox onClick's began breaking if I apply the theme directly to them with a 'android:theme="@style/CheckBoxTheme"', to the tune of this: java.lang.IllegalStateException: Could not find a method onLinkCheckboxClicked(View) in the activity class android.view.ContextThemeWrapper for onClick handler on view class android.support.v7.widget.AppCompatCheckBox with id 'chx_sub_all'
If I DON'T use android:theme on the checkBoxes and just let the RF_AppTheme do it's thing, I can alter the checkbox with android:buttonTint just fine. onClicks work no problem. (The reason I'm splitting this into it's own specific theme is because I want to support a lower version, so I have a 'value/styles.xml' that just changes the background color, and a 'values-r21/styles.xml' that uses buttonTint which is version 21+ )
From what I can tell, the theme being used is changing the version of CheckBox, so that it tries to look at an activity that isn't my MainActivity, which doesn't exist.
My theme is literally a copy/paste of the theme generated with the project, with more things added to it:
<resources>
<style name="RF_AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:background">@color/colorBackground</item>
<item name="android:textSize">@dimen/text_size</item>
<item name="android:textColor">@color/colorTextNormal</item>
<item name="android:buttonTint">@color/colorPrimaryLight</item>
</style>
<style name="CheckBoxTheme" parent="RF_AppTheme">
<item name="android:buttonTint">@color/colorPrimaryLight</item>
<item name="android:gravity">center_vertical</item>
</style>
</resources>
This is the general idea of what my MainActivity looks like, without all the other code copy/pasted over.
public class MainActivity extends AppCompatActivity {
//onStart and the like above
public void onLinkCheckboxClicked(View view)
{
//doing checkbox things here, which never gets called
}
}
and this is one of my checkboxes
<CheckBox android:id="@+id/chx_sub_all"
android:theme="@style/CheckBoxTheme"
android:text="@string/check_all"
android:textColor="@color/colorTextNormal"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="onLinkCheckboxClicked"/>
Aucun commentaire:
Enregistrer un commentaire