PR 10
PR 10
Q1. Write a program to create a login form for a social networking site.
Manifest File
<?xml version="1.0" encoding="utf-8"?> <action
<manifest android:name="android.intent.action.MAIN" />
xmlns:android="http://schemas.android.com/apk/res/
android" <category
android:name="android.intent.category.LAUNCHER
xmlns:dist="http://schemas.android.com/apk/distribut " />
ion" </intent-filter>
package="com.example.intent1"> </activity>
<activity android:name=".second">
<dist:module dist:instant="true" /> <intent-filter>
<action
<application android:name="android.intent.action.MAIN" />
android:allowBackup="true"
android:icon="@mipmap/ic_launcher" <category
android:label="@string/app_name" android:name="android.intent.category.LAUNCHER
" />
android:roundIcon="@mipmap/ic_launcher_round" </intent-filter>
android:supportsRtl="true" </activity>
android:theme="@style/AppTheme"> </application>
<activity android:name=".MainActivity"> </manifest>
<intent-filter>
XML Code:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?> android:layout_weight="1"/>
<LinearLayout </LinearLayout>
xmlns:android="http://schemas.android.com/apk/res/ <LinearLayout
android" android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res- android:layout_height="wrap_content"
auto" android:weightSum="2">
xmlns:tools="http://schemas.android.com/tools" <TextView
android:layout_width="match_parent" android:id="@+id/tv2"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:orientation="vertical" android:layout_height="wrap_content"
android:layout_marginTop="75dp" android:layout_weight="1"
tools:context=".MainActivity"> android:text="Password" />
<LinearLayout <EditText
android:layout_width="match_parent" android:id="@+id/et2"
android:layout_height="wrap_content" android:layout_width="wrap_content"
android:weightSum="2"> android:layout_height="wrap_content"
<TextView android:layout_weight="1"
android:id="@+id/tv1" android:ems="10"
android:layout_width="wrap_content" android:inputType="textPassword" />
android:layout_height="wrap_content" </LinearLayout>
android:text="Username" <Button
android:layout_weight="1"/> android:id="@+id/btn1"
<EditText android:layout_width="wrap_content"
android:id="@+id/et1" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center"
android:layout_height="wrap_content" android:layout_marginTop="50dp"
android:ems="10" android:text="LOGIN" />
android:inputType="textPersonName" </LinearLayout>
1
Practical 10
JAVA Code:
MainActivity.java
package com.example.intent1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
Button b1;
EditText e1,e2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
e1=(EditText)findViewById(R.id.et1);
e2=(EditText)findViewById(R.id.et2);
b1=(Button)findViewById(R.id.btn1);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
InputMethodManager imm=(InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(),0);
String s1=e1.getText().toString();
String s2=e2.getText().toString();
e1.getText().clear();
e2.getText().clear();
Intent i = new Intent(getApplicationContext(), second.class);
i.putExtra("Value1", s1);
i.putExtra("Value2", s2);
startActivity(i);
}
});
}
}
2
Practical 10
XML Code:
activity_second.xml:
<?xml version="1.0" encoding="utf-8"?> android:textSize="30dp"
<LinearLayout android:textAlignment="center"
xmlns:android="http://schemas.android.com/apk/res/ android:textColor="#FF000000"
android" android:layout_gravity="center"/>
android:orientation="vertical"
android:layout_width="wrap_content" <Button
android:layout_height="wrap_content" android:id="@+id/button"
android:layout_gravity="center"> android:layout_width="wrap_content"
android:layout_height="wrap_content"
<TextView android:layout_marginTop="6dp"
android:id="@+id/tview1" android:layout_gravity="center"
android:layout_width="wrap_content" android:text="EXIT"/>
android:layout_height="wrap_content" </LinearLayout>
JAVA Code:
second.java
package com.example.intent1;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
t1 = (TextView) findViewById(R.id.tview1);
bb=(Button)findViewById(R.id.button);
Bundle e=getIntent().getExtras();
String str1=e.getString("Value1");
String str2=e.getString("Value2");
if(str1.equals("BSIET")&&str2.equals("bsiet")) {
t1.setText("LOGIN SUCCESSFUL");
}
else{
t1.setText("LOGIN FAILED");
}
bb.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.exit(0);
}
});
}
}
3
Practical 10
Output: