【问题标题】:android:onClick is working slow for buttonandroid:onClick 按钮工作缓慢
【发布时间】:2020-09-25 23:39:12
【问题描述】:

从注册页面转到电话验证页面的 XML 代码:

<Button
    android:id="@+id/signup_btn"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="55dp"
    android:background="@drawable/btn"
    android:text="Sign up"
    android:onClick="toPhoneNumber"
    android:textColor="#fff"
    android:textColorLink="#CFC8C8"/>

更多Java文件代码:

 public void toPhoneNumber(View view) {
    startActivity(new Intent(this,SignUp2nd.class));
}

【问题讨论】:

  • 添加SignUp2nd的代码。延迟可能是在该活动的开始
  • 嘿@Ayush,你的代码是正确的。虽然这个回调不能让它变慢。我认为它与您的设备/模拟器或您的活动本身有关。为您的问题添加更多详细信息将有助于我们提出更多建议。

标签: android material-components-android material-components


【解决方案1】:

Ayush Dubey 在 OnClick 上尝试 addonclicklistner 我希望这会对您有所帮助。 这里是它的文档:https://developer.android.com/reference/android/widget/Button

示例:

  button.setOnClickListener(new View.OnClickListener() {
             public void onClick(View v) {
                 // Code here executes on main thread after user presses button
             }
         });

【讨论】:

  • 比使用 android:onClick 快吗?
  • 不,不会有任何区别。 XML 布局和类代码的回调功能是相同的。
猜你喜欢
  • 1970-01-01
  • 2014-09-01
  • 2017-02-25
  • 2013-10-01
  • 2018-11-21
  • 1970-01-01
  • 2013-07-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多