Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Suppose you are designing a login activity for your app. The app has two activit

ID: 3820807 • Letter: S

Question

Suppose you are designing a login activity for your app. The app has two activity (LoginActiviy, NewActivity). Write only the Java Code here for LoginActivity. The login activity is show in the following figure:

The user name will be “admin” and password “admin”. The user has only 3 attempts to try to login, for each wrong trail the number of attempts left will be decremented by one. Once the attempts left is zero the login button should be disabled.

If the user enters the user name and password correctly and press login, A new activity “NewActivity” should be opened using intent.

it448test lapp Login User Name Password Attempts Left LOGIN 6:00 etxtname etxtpass txtyleft btnlogin

Explanation / Answer

This is Java code you will need for your program. We have used counter to keep count of failed attempts and there is class available in android library to mark enabled button as false and we will see it disabled

public class MainActivity extends Activity {

   Button loginBtn;

   TextView etxtname, etxtpass;

   TextView textView;

   int counter = 3;

   @Override

   protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

loginBtn = (Button)findViewById(R.id.button);

etxtname = (TextView)findViewById(R.id.editText);

etxtpass = (TextView)findViewById(R.id.editText2);

loginBtn.setOnClickListener(new View.OnClickListener() {

   @Override

   public void onClick(View v) {

if(etxtname.getText().toString().equals("admin") &&

   etxtpass.getText().toString().equals("admin")) {

Toast.makeText(getApplicationContext(),

   "Redirecting...",Toast.LENGTH_SHORT).show();

   }else{

Toast.makeText(getApplicationContext(), "Wrong

   Credentials",Toast.LENGTH_SHORT).show();

textView.setVisibility(View.VISIBLE);

textView.setBackgroundColor(Color.RED);

counter--;

textView.setText(Integer.toString(counter));

if (counter == 0) {

   loginBtn.setEnabled(false);

}

   }

   }

});

   }

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote