Using Android Studio)Suppose you are designing a login activity for your android
ID: 3845649 • Letter: U
Question
Using Android Studio)Suppose you are designing a login activity for your android app. The android 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.
it448testlapp Login User Name Password Attempts Left LOGIN 6:00 etxtname etxt passExplanation / Answer
package com.example.mylaptop.chegg; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity { EditText ed1,ed2,ed3; Button b1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ed1=(EditText)findViewById(R.id.ed1); ed2=(EditText)findViewById(R.id.ed2); ed3=(EditText)findViewById(R.id.ed3); b1=(Button)findViewById(R.id.b1); String str1,str2,str3; int num=3; str1=ed1.getText().toString(); str2=ed2.getText().toString(); str3=Integer.toString(num); ed3.setText(str3); if(str1.equals("admin") && str2.equals("admin")) { Intent i=new Intent(MainActivity.this,NewActivity.class); startActivity(i); } else { num--; String str4=ed3.getText().toString(); if(str4.equals("0")) { b1.setEnabled(false); } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.