So, I want a button like this in my app:
I don't know how to add code for button in the android-studio, and I only have the scanner code. I don't know how to put 2 function in the same project. What should I do? Can someone help me?
It sounds like you need to add a function to handle the OnClick
event. 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.
}
});
}
}