【发布时间】:2018-01-21 20:31:49
【问题描述】:
所以,我想在我的应用程序中添加一个这样的按钮:
我不知道如何在 android-studio 中为按钮添加代码,我只有扫描仪代码。我不知道如何将 2 个函数放在同一个项目中。我该怎么办?有人能帮我吗?
【问题讨论】:
标签: java android generator qr-code barcode-scanner
所以,我想在我的应用程序中添加一个这样的按钮:
我不知道如何在 android-studio 中为按钮添加代码,我只有扫描仪代码。我不知道如何将 2 个函数放在同一个项目中。我该怎么办?有人能帮我吗?
【问题讨论】:
标签: java android generator qr-code barcode-scanner
听起来您需要添加一个函数来处理OnClick 事件。 The Android documentation has a nice example on how to set and OnClick listener:
<Button
android:id="@+id/button_id"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/self_destruct" />
public class MyActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.content_layout_id);
final Button button = findViewById(R.id.button_id);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Code here executes on main thread after user presses button
// This should be where you add your button logic.
}
});
}
}
【讨论】:
MainActivity。默认情况下,如果您没有创建空项目,清单应该没问题。