0% found this document useful (0 votes)
5 views

Practical 7 code

The document contains two XML layouts and corresponding Java code for Android applications. The first layout is for a user login interface with fields for username and password, while the second layout collects personal information including name, date of birth, and blood group. Both applications feature a submit button that displays the entered information in a TextView upon clicking.

Uploaded by

anujkothawale93
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)
5 views

Practical 7 code

The document contains two XML layouts and corresponding Java code for Android applications. The first layout is for a user login interface with fields for username and password, while the second layout collects personal information including name, date of birth, and blood group. Both applications feature a submit button that displays the entered information in a TextView upon clicking.

Uploaded by

anujkothawale93
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/ 5

1:-

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


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10sp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Username"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Username"
android:hint="@string/Username"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Password"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Password"
android:hint="@string/Password"
android:inputType="textPassword"/>

</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Submit"
android:id="@+id/Submit"
android:layout_gravity="center"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Display"
android:text=""
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="@color/black"/>

</LinearLayout>

package com.example.edit;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText username=findViewById(R.id.Username);
EditText password=findViewById(R.id.Password);
Button submit=findViewById(R.id.Submit);
TextView display=findViewById(R.id.Display);

submit.setOnClickListener(v->{
String Username=username.getText().toString();
String Password=password.getText().toString();
display.setText(getString(R.string.Display,Username,Password));
}
);
}
}

2:-
<?xml version="1.0" encoding="utf-8" ?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10sp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Name"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/Name"
android:hint="@string/Name"
android:inputType="textPersonName"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/DOB"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/DOB"
android:hint="@string/DOB"
android:inputType="date"/>

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/BloodGroup"/>

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/BloodGroup"
android:hint="@string/BloodGroup"/>

</LinearLayout>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Submit"
android:id="@+id/Submit"
android:layout_gravity="center"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/Display"
android:text=""
android:layout_gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="@color/black"/>

</LinearLayout>

package com.example.edit;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends Activity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText name=findViewById(R.id.Name);
EditText dob=findViewById(R.id.DOB);
EditText bloodGroup=findViewById(R.id.BloodGroup);
Button submit=findViewById(R.id.Submit);
TextView display=findViewById(R.id.Display);

submit.setOnClickListener(v->{
String Name=name.getText().toString();
String Dob=dob.getText().toString();
String BloodGroup=bloodGroup.getText().toString();
display.setText(getString(R.string.Display,Name,Dob,BloodGroup));
}
);

}
}

You might also like