【问题标题】:Where should I put android button function我应该把android按钮功能放在哪里
【发布时间】:2015-11-04 09:42:55
【问题描述】:

我知道如何在 XML 中制作按钮,但我不知道应该把我的函数放在哪里。我应该把它放在 layout 还是 drawable 上?如果我按下该按钮,如何调用我的脚本。

【问题讨论】:

    标签: android android-layout android-button


    【解决方案1】:

    与您的 XML 文件相关的类的典型代码 sn-p 如下:

    final Button button = (Button) findViewById(R.id.button_id);
    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            // Perform action on click
        }
    });
    

    参考:http://developer.android.com/reference/android/widget/Button.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-09-30
      • 2016-08-25
      • 2013-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多