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

Requirements The application will let the user enter user name and password in o

ID: 3747637 • Letter: R

Question

Requirements The application will let the user enter user name and password in one activity, and then display some prompt information on another activity. Here are the important characteristics There should be two components for the user to enter the user name and password in the first activity. Each of these should have a descriptive label to the left. The two input components should appear above each other There should be a button to cause the addition to happen in the first activity » . Use a vertical linear layout with horizontal layouts to get the screen to look as much like the sample as you can. Make sure the action button is centered. . Use string resources for the various labels on the application If the inputted user name and password are matched, then display some congratulation messages on another activity o For simplicity, set the valid user name to "cs4322", and set the password to "123456 Otherwise, display login failed messages on another activity o In the second activity: There should be a component to display login failed information. Moreover, there should be a button placed under the display component. When the user clicks on the button, the application goes back to the previous login activity Here are the screenshots of the lab application 7:40 er Name cS2302 s2302, Welcome to my webpagel Login

Explanation / Answer

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="myfirstapp.simpleloginapp">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:supportsRtl="true"

android:theme="@style/AppTheme">

<activity android:name=".login">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".user">

<intent-filter>

<action android:name="myfirstapp.simpleloginapp.user" />

<category android:name="android.intent.category.DEFAULT" />

</intent-filter>

</activity>

</application>

</manifest>

Login Activity – (first Activity ) – Login.java

package myfirstapp.simpleloginapp;

import android.content.Intent;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

public class login extends AppCompatActivity {

private static EditText username;

private static EditText password;

private static TextView attempts;

private static Button login_btn;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_login);

login_button();

}

public void login_button() {

username = (EditText) findViewById(R.id.editText_user);

password = (EditText) findViewById(R.id.editText_password);

attempts = (TextView) findViewById(R.id.textView_attemptcounter);

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

login_btn.setOnClickListener(

new View.OnClickListener(){

@Override

public void onClick(View v) {

if (username.getText().toString().equals("cs4322") &&

password.getText().toString().equals("123456")) {

Toast.makeText(login.this, "User name and password is Correct ",

Toast.LENGTH_SHORT).show();

//create an intent and open the new activity

Intent intent =new Intent("myfirstapp.simpleloginapp.user");

startActivity(intent);

} else {

Toast.makeText(login.this, "User name and password is NOT Correct

", Toast.LENGTH_SHORT).show();

}

}

}

);

}// closing for listener method

} // closing for class

Second Activity - User.java

package myfirstapp.simpleloginapp;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;

public class user extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_user);

}

}

Strings.xml

<resources>

<string name="app_name">SimpleLoginApp</string>

<string name="login_page">Login Page</string>

<string name="user_name">User Name</string>

<string name="password">Password</string>

<string name="name">Name</string>

<string name="attempts">Attempts</string>

<string name="login">LOGIN</string>

<string name="welcome_to_the_second_page">Welcome to the Second page</string>

</resources>

Activity_login.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="myfirstapp.simpleloginapp.login">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceLarge"

android:text="@string/login_page"

android:id="@+id/textView"

android:layout_alignParentTop="true"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="@string/user_name"

android:id="@+id/textView2"

android:layout_marginTop="68dp"

android:layout_below="@+id/textView"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceMedium"

android:text="@string/password"

android:id="@+id/textView3"

android:layout_below="@+id/editText_user"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_marginTop="50dp" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:inputType="textPersonName"

android:text="@string/name"

android:ems="10"

android:id="@+id/editText_user"

android:layout_alignBottom="@+id/textView2"

android:layout_toRightOf="@+id/textView"

android:layout_toEndOf="@+id/textView" />

<EditText

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:inputType="textPassword"

android:ems="10"

android:id="@+id/editText_password"

android:layout_alignTop="@+id/textView3"

android:layout_alignLeft="@+id/editText_user"

android:layout_alignStart="@+id/editText_user" />

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceLarge"

android:text="@string/attempts"

android:id="@+id/textView4"

android:layout_below="@+id/editText_password"

android:layout_alignParentLeft="true"

android:layout_alignParentStart="true"

android:layout_marginTop="68dp" />

<TextView

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceLarge"

android:id="@+id/textView_attemptcounter"

android:layout_alignTop="@+id/textView4"

android:layout_alignLeft="@+id/editText_password"

android:layout_alignStart="@+id/editText_password" />

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="@string/login"

android:id="@+id/button"

android:layout_below="@+id/textView4"

android:layout_toRightOf="@+id/textView3"

android:layout_toEndOf="@+id/textView3"

android:layout_marginTop="48dp" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageView"

android:src="@android:drawable/ic_secure"

android:scaleType="fitCenter"

android:layout_alignBottom="@+id/textView"

android:layout_centerHorizontal="true" />

<ImageView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/imageView2"

android:src="@mipmap/ic_launcher"

android:layout_alignParentTop="true"

android:layout_alignParentRight="true"

android:layout_alignParentEnd="true" />

</RelativeLayout>

Activity_user.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context="myfirstapp.simpleloginapp.user">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textAppearance="?android:attr/textAppearanceLarge"

android:text="@string/welcome_to_the_second_page"

android:id="@+id/textView5"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="93dp" />

</RelativeLayout>

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