Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- main activity xml :
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context="com.example.jan25.mytask3.MainActivity">
- <LinearLayout
- android:layout_width="376dp"
- android:layout_height="30dp"
- android:orientation="vertical"
- tools:layout_editor_absoluteX="8dp"
- tools:layout_editor_absoluteY="8dp">
- <TextView
- android:id="@+id/logPage"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:gravity="center"
- android:text="LogIn Page" />
- </LinearLayout>
- <LinearLayout
- android:layout_width="373dp"
- android:layout_height="142dp"
- android:orientation="vertical"
- tools:layout_editor_absoluteX="6dp"
- tools:layout_editor_absoluteY="122dp">
- <EditText
- android:id="@+id/usertxt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:ems="10"
- android:inputType="textPersonName"
- android:text="@string/userName" />
- <EditText
- android:id="@+id/passtxt"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:ems="10"
- android:inputType="textPersonName"
- android:text="@string/userPass" />
- <Button
- android:id="@+id/btnsign"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:onClick="onClick"
- android:text="@string/button"
- tools:text="Sign In" />
- </LinearLayout>
- </android.support.constraint.ConstraintLayout>
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- main activity java
- package com.example.jan25.mytask3;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.EditText;
- import android.widget.Toast;
- public class MainActivity extends AppCompatActivity implements View.OnClickListener {
- final String USERNAME_DB = "Jan", USERPASS_DB = "123";
- EditText usertxt, passtxt;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- setPointer();
- }
- public void setPointer() {
- usertxt = findViewById(R.id.usertxt);
- passtxt = findViewById(R.id.passtxt);
- }
- @Override
- public void onClick(View view) {
- String userName = usertxt.getText().toString();
- String userPass = passtxt.getText().toString();
- switch (view.getId()) {
- case R.id.btnsign:
- if (userName.equals(USERNAME_DB)) {
- if (userPass.equals(USERPASS_DB))
- Toast.makeText(MainActivity.this, getString(R.string.loginSuccess), Toast.LENGTH_SHORT).show();
- }
- else {
- Toast.makeText(MainActivity.this, getString(R.string.loginErrorUserNull), Toast.LENGTH_SHORT).show();
- }
- }
- }
- }
- +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- strings
- <resources>
- <string name="app_name">myTask3</string>
- <string name="userName">Enter Username </string>
- <string name="userPass">Enter Password </string>
- <string name="button">Sign In </string>
- <string name="loginSuccess">Login successful</string>
- <string name="loginErrorUserNull">Invalid username or password</string>
- </resources>
- ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement