Question: i need help fixing my code. the problem is The functionality of the buttons: Count: Adds 1 to the current count Double: Doubles the current

i need help fixing my code. the problem is The functionality of the buttons:
Count: Adds 1 to the current count
Double: Doubles the current count value when pressed
Reset: Sets the count value back to 0
Toast: Displays a toast message of your choice
Toggle: Turns the background image's visibility from VISIBLE to GONE and when pressed again it changes it from GONE to VISIBLE
Additional Requirements
Adding an ImageView that displays behind the count text (This is what the Toggle buttons change the visibility of)
Change the name of the app in the manifest file and make it "Layout App"
At least one onClick method should be attached in the onCreate method (with an anonymous function or lambda expression)
The TOAST and TOGGLE buttons are inside a linearLayout (horizontal) to achieve the side-by-side look (hint: layout_weight is used)
All displayed text should be a String resource rather than a hardcoded String
A screenshot image of the completed app, looking similar to the one above, is to be added to your zipped folder my code is this and i already have the activity_main and strings file just need the java code. buttons: {
private int count =0;
private ImageView backgroundImage;
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Initialize views
TextView countText = findViewById(R.id.countText);
Button btnCount = findViewById(R.id.btnCount);
Button btnDouble = findViewById(R.id.btnDouble);
Button btnReset = findViewById(R.id.btnReset);
Button btnToast = findViewById(R.id.btnToast);
Button btnToggle = findViewById(R.id.btnToggle);
// Set onClick listeners
btnCount.setOnClickListener(v ->{
count++;
countText.setText(getString(R.string.count_default_text, count));
});
btnDouble.setOnClickListener(v ->{
count *=2;
countText.setText(getString(R.string.count_default_text, count));
});
btnReset.setOnClickListener(v ->{
count =0;
countText.setText(getString(R.string.count_default_text, count));
});
btnToast.setOnClickListener(v -> showToast(getString(R.string.toast_message)));
btnToggle.setOnClickListener(v -> toggleVisibility());
}
private void showToast(String message){
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}
private void toggleVisibility(){
int visibility =(backgroundImage.getVisibility()== View.VISIBLE)? View.GONE : View.VISIBLE;
backgroundImage.setVisibility(visibility);
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!