MAD Manual

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

Practical No. 4: Develop a program to display Hello World on screen.

X. Exercise.

1. Write a program to display HelloWorld.

Xml file:

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


<androidx.constraintlayout.widget.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=".MainActivity">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java file:

package com.example.manual;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

public class MainActivity extends AppCompatActivity {

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

2. Write a program to display student name and marks.

xml file:

<?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=".MainActivity">

<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_marginTop="190dp"
android:layout_marginLeft="100dp"

/>
<TextView
android:id="@+id/marks"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text=""
android:layout_marginLeft="100dp"
android:layout_marginTop="220dp"
/>
</RelativeLayout>

Java file:

package com.example.manual;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


TextView name,mark;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (TextView) findViewById(R.id.name);
mark = (TextView) findViewById(R.id.marks);
name.setText("Student name: Rahul Patil");
mark.setText("Marks: 85.60%");
}
}
Output:-
Practical No. 5: Develop a program to implement linear layout and absolute layout.
X. Exercise.

1. Write a program to place Name, Age and mobile number linearly (Vertical) on the display screen using Linear
layout.

Xml file:

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


<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="25dp"
/>
<TextView
android:id="@+id/marks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="25dp"
/>
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:textSize="25dp" />
</LinearLayout>

Java File:

package com.example.manual;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView name,mark,number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (TextView) findViewById(R.id.name);
mark = (TextView) findViewById(R.id.marks);
number = (TextView) findViewById(R.id.number);
name.setText("Name.");
mark.setText("Age.");
number.setText("Mobile Number.");
}

Output:-

2. Write a program to place Name, Age and mobile number centrally on the display screen using Absolute
layout.
Xml file:

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


<AbsoluteLayout 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="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_x="450px"
android:layout_y="100px"
android:textSize="25dp" />
<TextView
android:id="@+id/marks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_x="450px"
android:layout_y="180px"
android:textSize="25dp" />
<TextView
android:id="@+id/number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:layout_x="450px"
android:layout_y="260px"
android:textSize="25dp" />
</AbsoluteLayout>

Java file:

package com.example.manual;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView name,mark,number;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (TextView) findViewById(R.id.name);
mark = (TextView) findViewById(R.id.marks);
number = (TextView) findViewById(R.id.number);
name.setText("Name.");
mark.setText("Age.");
number.setText("Mobile Number.");
}

Output:-

Page no 29
Practical No. 6: Develop a program to implement frame layout, table
layout and relative layout.
X. Exercise.

1. Write a program to display 10 students basic information in a table form using Table layout.

Code:-

Xml file:-

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


<TableLayout 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:layout_marginTop="50dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
tools:context=".MainActivity">
<TableRow android:background="#00FFFF" android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Roll no"
android:textAlignment="center"
android:layout_weight="0.1”/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textAlignment="center"
android:layout_weight="1”/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textAlignment="center"
android:layout_weight="0.2"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Rahul Kumar"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="19"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gadhinglaj"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Amar Patil"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="19"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ajra"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="3"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sachin Kalasgonda"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="18"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gadhinjlaj"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="4"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sanket Bhandugare"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Keral"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="5"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Pravin Khot"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gujarat"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="6"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Aditya Sambhaji"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gadhinglaj"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="7"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Sanket Patil"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="19"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gadhinglaj"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="8"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Maaj Bhadgaokar"
            android:textAlignment="center"
            android:layout_weight="1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="19"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ajra"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="9"
            android:textAlignment="center"
            android:layout_weight="0.1"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Atharv Sultanpure"
            android:textAlignment="center"
            android:layout_weight="1"
            />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="20"
            android:textAlignment="center"
            android:layout_weight="0.2"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Gadhinglaj"
            android:textAlignment="center"
            android:layout_weight="1"/>
    </TableRow>
    <TableRow android:background="#ade2e6" android:padding="5dp">
        <TextView
            android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="10"
android:textAlignment="center"
android:layout_weight="0.1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Malhar Kulkarni"
android:textAlignment="center"
android:layout_weight="1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="19"
android:textAlignment="center"
android:layout_weight="0.2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gadhinglaj"
android:textAlignment="center"
android:layout_weight="1" />
</TableRow>
</TableLayout>

Java File:-

package com.example.autocompletetext;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}

Output:-

2. Write a program to display all the data types in object-oriented programming using Frame layout.
Code:-

Xml file:-
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="40dp"
android:id="@+id/frameLayout">

<TextView
android:id="@+id/intTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="25dp"/>

<TextView
android:id="@+id/floatTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"/>

<TextView
android:id="@+id/doubleTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="55dp"/>

<TextView
android:id="@+id/booleanTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="70dp"/>

<TextView
android:id="@+id/stringTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="85dp"/>

<TextView
android:id="@+id/charTextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="100dp"/>

</FrameLayout>
Java file:-
package com.example.autocompletetext;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


String[] datatype = {"int", "float", "double", "boolean", "string", "char"};
String[] datatypeDesc = {"This is an integer datatype",
"This is a float datatype",
"This is a string datatype",
"This is a boolean datatype",
"This a a double datatype",
"This a chars datatype"};

FrameLayout frameLayout;
TextView textView1,textView2,textView3,textView4,textView5,textView6;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = findViewById(R.id.frameLayout);
textView1 = findViewById(R.id.intTextView);
textView2 = findViewById(R.id.floatTextView);
textView3 = findViewById(R.id.stringTextView);
textView4 = findViewById(R.id.booleanTextView);
textView5 = findViewById(R.id.doubleTextView);
textView6 = findViewById(R.id.charTextView);

textView1.setText(datatype[0]+": "+datatypeDesc[0]);
textView2.setText(datatype[1]+": "+datatypeDesc[1]);
textView3.setText(datatype[2]+": "+datatypeDesc[2]);
textView4.setText(datatype[3]+": "+datatypeDesc[3]);
textView5.setText(datatype[4]+": "+datatypeDesc[4]);
textView6.setText(datatype[5]+": "+datatypeDesc[5]);
}
}

Output:-

Practical No. 7: Develop a program to implement Text View and Edit Text.
X. Exercise.

1. Write a program to accept username and password from the end user using Text
View and Edit Text.

Xml file:

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


<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">

<TextView
android:layout_marginTop="150dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Username"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginLeft="100dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Password"
/>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:layout_marginLeft="100dp"
android:inputType="textPassword"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Login"
/>
</LinearLayout>

Output:

2. Write a program to accept and display personal information of the student.

Xml code:

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


<LinearLayout 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:orientation="vertical"
tools:context=".MainActivity">

<EditText
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Name"
android:layout_marginTop="100dp"
android:layout_marginLeft="10dp"
/>
<EditText
android:id="@+id/sname"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Surname"
android:layout_marginLeft="10dp"
android:inputType="textPersonName"
/>
<EditText
android:id="@+id/mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Mobile"
android:layout_marginLeft="10dp"
android:inputType="number"
/>
<EditText
android:id="@+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Email"
android:layout_marginLeft="10dp"
android:inputType="textEmailAddress"
/>
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="Submit"
/>
<TextView
android:id="@+id/result"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="30dp"
android:textSize="18dp"
/>
</LinearLayout>

Java code:

package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


EditText name,sname,mob,email;
Button btn;
TextView result;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.name);
sname = (EditText) findViewById(R.id.sname);
mob = (EditText) findViewById(R.id.mobile);
email = (EditText) findViewById(R.id.email);
btn = (Button) findViewById(R.id.btn);
result = (TextView) findViewById(R.id.result);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
result.setText("Name: "+name.getText().toString()+" "+sname.getText().toString()+"\n"+"Mobile:
"+mob.getText().toString()+"\n"+"Email: "+email.getText().toString()+"\n");
}
});
}
}

Output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy