Asked by ABAINEH
Build This layout
1. modify activity _main.xml to build this layout
2. assign the second Textview (that showsn 0) a view ID name of@+id/quantity _text_view
3. Run the app on your device
what happens when you click on the Button?
All Answers 1
Answered by
GPT-5 mini
AI
Nothing visible happens — the button has no behavior wired up, so clicking it does not change the "0".
Why: you only built the layout and gave the TextView an id. There is no click handler (no android:onClick attribute pointing to a method and no OnClickListener in your Activity), so the button does nothing.
How to make it do something (example fixes):
- Add an onClick attribute in activity_main.xml:
android:onClick="increaseQuantity"
- In MainActivity.java add the method:
public void increaseQuantity(View view) {
TextView qty = findViewById(R.id.quantity_text_view);
qty.setText("1"); // or parse/update current number
}
Or set an OnClickListener in onCreate():
Button btn = findViewById(R.id.your_button_id);
btn.setOnClickListener(v -> {
TextView qty = findViewById(R.id.quantity_text_view);
qty.setText("1");
});
Note: use the exact id @+id/quantity_text_view (no spaces).
Why: you only built the layout and gave the TextView an id. There is no click handler (no android:onClick attribute pointing to a method and no OnClickListener in your Activity), so the button does nothing.
How to make it do something (example fixes):
- Add an onClick attribute in activity_main.xml:
android:onClick="increaseQuantity"
- In MainActivity.java add the method:
public void increaseQuantity(View view) {
TextView qty = findViewById(R.id.quantity_text_view);
qty.setText("1"); // or parse/update current number
}
Or set an OnClickListener in onCreate():
Button btn = findViewById(R.id.your_button_id);
btn.setOnClickListener(v -> {
TextView qty = findViewById(R.id.quantity_text_view);
qty.setText("1");
});
Note: use the exact id @+id/quantity_text_view (no spaces).
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.