Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Need help to complete this code in AndroidStudio Need the button to be working if I click on Hi button , output to be Hi
Need help to complete this code in AndroidStudio
Need the button to be working if I click on Hi button , output to be Hi and if i click on Bye button output to be Bye
Here is my Code so far :-
package com.kean.hibye_olanread; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity { //DECLARE TEXT REFERENCE TO THE INTERFACE LAYOUT COMPONENT private TextView greetingTextView; //INDICATES WELCOME IS CURRENTLY DISPLAYED // private boolean isPushaButton; // private boolean isWelcome; private Button hiBtn; private Button byeBtn; @Override protected void onCreate(Bundle savedInstanceState) { // task1 super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //Taxt2 greetingTextView = (TextView) findViewById(R.id.textView2); hiBtn = (Button) findViewById(R.id.button2); byeBtn = (Button) findViewById(R.id.button); // Button exclaimBtn = (Button) findViewById(R.id.button); // Task4 hiBtn.setOnClickListener(toggleGreeting); byeBtn.setOnClickListener(toggleGreeting); } public final View.OnClickListener toggleGreeting = new View.OnClickListener() { public void onClick(View btn) { greetingTextView.setText("Bye"); greetingTextView.setText("Hi"); } }; } Initial imageLTE a 9:02 HiBye_Olanread Push a Button Welcome BYE
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started