Android
  • 官方文件
  • Android studio
    • Layout Editor
    • WebView
    • 發佈
    • 常見問題
  • 專案架構
    • AndroidManifest.xml
  • 程式相關
    • Material Design
    • 隱藏 title bar
    • HTTP GET
    • 使用 Java 8
    • onClick
    • 新增畫面
    • delay
    • Layout 檔案設定
    • WebRTC
  • listView
Powered by GitBook
On this page

Was this helpful?

  1. 程式相關

onClick

Previous使用 Java 8Next新增畫面

Last updated 4 years ago

Was this helpful?

有幾種寫法

1.Lambda

        Button b = findViewById(R.id.button1);
        b.setOnClickListener(view -> {
            System.out.println(123);
            new AlertDialog.Builder(c)
                    .setMessage("test")
                    .show();
        });

2.

final Context c = this;
mButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        // do something here
    }
});

https://stackoverflow.com/questions/30752547/what-does-it-mean-that-a-listener-can-be-replaced-with-lambda