0% found this document useful (0 votes)
7 views7 pages

mada 17

The document contains two Android XML layout files and their corresponding Java activity classes for a simple application. The first layout and activity handle user login with username and password validation, while the second layout and activity compare two numbers input by the user. Both activities update a TextView with the result of their respective operations.

Uploaded by

lochansawant0107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views7 pages

mada 17

The document contains two Android XML layout files and their corresponding Java activity classes for a simple application. The first layout and activity handle user login with username and password validation, while the second layout and activity compare two numbers input by the user. Both activities update a TextView with the result of their respective operations.

Uploaded by

lochansawant0107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

• Activity_main.

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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/white">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="USERNAME:"
android:textSize="20dp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_marginTop="300dp"
android:layout_marginLeft="30dp"
android:id="@+id/text"
/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter the username"
android:textColorHint="@color/black"
android:layout_marginLeft="150dp"
android:textColor="#010A12"
android:textStyle="bold"
android:layout_marginTop="290dp"
android:id="@+id/edi"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PASSWORD:"
android:textColor="@color/black"
android:textStyle="bold"
android:layout_marginTop="350dp"
android:textSize="20dp"
android:layout_marginLeft="30dp"
android:id="@+id/view"/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter your password"
android:textColorHint="@color/black"
android:layout_marginTop="340dp"
android:layout_marginLeft="150dp"
android:textStyle="bold"
android:textColor="#010A12"
android:id="@+id/edit"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_marginTop="400dp"
android:textStyle="bold"
android:layout_marginLeft="140dp"
android:id="@+id/but"/>
<ImageView
android:layout_width="1500dp"
android:layout_height="150dp"
android:src="@drawable/img"
android:layout_marginTop="110dp"
android:id="@+id/im"/>
<ImageView
android:layout_width="1500dp"
android:layout_height="2500dp"
android:src="@drawable/img_3"
android:layout_marginTop="500dp"
android:id="@+id/imh"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESULT"
android:layout_marginTop="480dp"
android:layout_marginLeft="160dp"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="@color/black"
android:id="@+id/textview1"/>
</RelativeLayout>

• MainActivity.java

package com.example.myapplication;

import static com.example.myapplication.R.id.main;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends Activity {
TextView text;
TextView view;
Button but;
EditText edit;
EditText edi;
ImageView im;
ImageView imh;
TextView textView1;

@Override
protected void onCreate(Bundle abc){
super.onCreate(abc);
setContentView(R.layout.activity_main);
text=findViewById(R.id.text);
view=findViewById(R.id.view);
but=findViewById(R.id.but);
edi=findViewById(R.id.edi);
edit=findViewById(R.id.edit);
imh=findViewById(R.id.imh);
im=findViewById(R.id.im);

but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username=edi.getText().toString();
String password=edit.getText().toString();
if(username.equals("lochan") && password.equals("2005"))
{
textView1.setText("Login successfull!");
}
else{
textView1.setText("Login Unsuccessfull!");
}

}
});

}
}
• Activity_main.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#D8BFD8">

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter the number"
android:textColorHint="@color/black"
android:layout_marginLeft="130dp"
android:textColor="#010A12"
android:textStyle="bold"
android:layout_marginTop="240dp"
android:id="@+id/edi"
/>

<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter the number"
android:textColorHint="@color/black"
android:layout_marginTop="290dp"
android:layout_marginLeft="130dp"
android:textStyle="bold"
android:textColor="#010A12"
android:id="@+id/edit"/>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="submit"
android:layout_marginTop="370dp"
android:textStyle="bold"
android:layout_marginLeft="150dp"
android:id="@+id/but"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result"
android:layout_marginTop="440dp"
android:layout_marginLeft="170dp"
android:textStyle="bold"
android:textSize="20dp"
android:textColor="@color/black"
android:id="@+id/textview1"/>

</RelativeLayout>

• MainActivity.java
package com.example.myapplication;

import static com.example.myapplication.R.id.main;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends Activity {

Button but;
EditText edit;
EditText edi;
TextView textView1;

@Override
protected void onCreate(Bundle abc){
super.onCreate(abc);
setContentView(R.layout.activity_main);

but=findViewById(R.id.but);
edi=findViewById(R.id.edi);
edit=findViewById(R.id.edit);
textView1=findViewById(textView1);

but.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int num1 =Integer.parseInt(edit.getText().toString());
int num2 =Integer.parseInt(edi.getText().toString());
if(num1>num2)
{
textView1.setText(num1+"is greater");
}
else if(num1==num2)
textView1.setText("both numbers are equal");
}
else
{

textView1.setText(num2 + "is greater");


}
});

}
}

You might also like