Nothing Special   »   [go: up one dir, main page]

Activity XML

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Activity xml

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


<RelativeLayout 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"
android:visibility="visible"
tools:context=".MainActivity">

<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:textSize="24sp" />

<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/name"
android:hint="Password"
android:textSize="24sp" />

<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/password"
android:lineSpacingExtra="36sp"
android:layout_centerHorizontal="true"
android:text="Sign in" />

</RelativeLayout>

Mainactivity.java

package com.example.bishal_2.myapplication;

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.Toast;

public class MainActivity extends AppCompatActivity {

private EditText Username;


private EditText Password;
private Button Login;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Username = (EditText)findViewById(R.id.name);
Password = (EditText)findViewById(R.id.password);
Login = (Button)findViewById(R.id.btn);

Login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
validate(Username.getText().toString(), Password.getText().toString());
}
});

public void validate(String username, String uspassword){


if((username.equals("Alpesh"))){
if(uspassword.equals("Alpesh")){
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
startActivity(intent);
}
}
else{
Toast.makeText(MainActivity.this,"Default User name and password is
Alpesh",Toast.LENGTH_LONG).show();
}
}

Main2activity

package com.example.bishal_2.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class Main2Activity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
}
}

Activity_main2.xml

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


<RelativeLayout 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=".Main2Activity">

<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="This is second activity"
android:textSize="30sp" />

</RelativeLayout>

You might also like