AppCompatButton android:onClick无法找到方法异常

时间:2017-05-17 15:16:48

标签: android android-4.4-kitkat

我在KitKat版本上有这个问题,其余的从16个API级别到25个工作正常

实例化布局的类具有布局方法,例如

select school_name, course,
grade,
sum(grade)
(select          
schools.name as school_name,            
courses.name as course,   
    CASE
         WHEN   ((studentgrades.averageScore / 50  * 100)  > 79)
              THEN 'A' 
              WHEN   ((studentgrades.averageScore / 50  * 100)  < 80) 
                     AND ((studentgrades.averageScore / 50  * 100)  >64)
              THEN 'B' 
              WHEN   ((studentgrades.averageScore / 50  * 100)  < 80) 
                     AND ((studentgrades.averageScore / 50  * 100)  >64)
              THEN 'C' 
              WHEN   ((studentgrades.averageScore / 50  * 100)  < 50)
              THEN 'D'                         
      END as grade,             
count(*)                 
from
students,
studentgrades,
schools,
courses
where
studentgrades.studentid = students.studentid
and studentgrades.schoolid = students.schoolid     
and studentgrades.schoolid = schools.school_number 
and courses.id = studentgrades.coursesid
and studentgrades.averageScore is not null 
and schools.name = 'St. Joe School'           
group by schools.name,  courses.name,standardsgrades.averageScore)
group by grade order by grade;

我知道我可以将此更改为听众,数据绑定或使用像Butterknife这样的库,但我有兴趣知道为什么只是崩溃4.X版本?

xml布局

<android.support.v7.widget.AppCompatButton
  android:onClick="onClick"
...
public void onClick(View v) {
  // do something
}

2 个答案:

答案 0 :(得分:3)

我找到了一些关于这个问题的解释。它是作为一个错误提交的。这是bug报告的链接。 https://issuetracker.google.com/issues/37108938

在一个要点中,他们说问题已在API 24中修复,onClick与支持库不兼容。我在关于kitkat问题的帖子中添加了评论。

答案 1 :(得分:0)

有一种解决方法。它在API 19上测试并且运行良好

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Button"
        android:onClick="onClick" />

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        style="@style/appCompatButtonStyle"   // Note this
        android:text="Button"
        android:onClick="onClick" />
</LinearLayout>

在你的styles.xml中

<style name="appCompatButtonStyle" parent="Widget.AppCompat.Button.Colored">
    <item name="backgroundTint">@color/colorWhite</item>
    <item name="android:textColor">@color/colorMaterialGrey</item>
</style>