Activity - Main - XML:: 3 and 4 A.
Activity - Main - XML:: 3 and 4 A.
Activity - Main - XML:: 3 and 4 A.
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/nmims"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="vertical"
android:layout_weight="8"
android:gravity="center_horizontal"
android:weightSum="10"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textColor="@color/red"
android:textStyle="bold"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Intro"
android:textColor="@color/red"
android:textStyle="bold"
android:layout_weight="1"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/prg"
android:textColor="@color/red"
android:textStyle="bold"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/topic"
android:textColor="@color/red"
android:textStyle="bold"
android:layout_weight="1"/>
<ImageView
android:id="@+id/gif"
android:layout_width="match_parent"
android:layout_height="174dp"
android:src="@drawable/android"
android:layout_weight="5"
>
</ImageView>
<TextView
android:id="@+id/next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/next"
android:textColor="@color/red"
android:textStyle="bold"
android:textSize="@dimen/medium"
android:layout_weight="1"
/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/androiddev"
android:layout_weight="1"
>
</ImageView>
</LinearLayout>
b. MainActivity.java: package com.example.practical34;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
TextView tv;
ImageView iv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv=findViewById(R.id.next);
iv=findViewById(R.id.gif);
iv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent in=new Intent(MainActivity.this,
Main3Activity.class); startActivity(in);
}
});
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(MainActivity.this,
Main2Activity.class));
}
});
}
}
c. Activity_main2.xml:
<?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:weightSum="10"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/nmims"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/blue"
android:orientation="vertical"
android:layout_weight="8"
android:gravity="center_horizontal"
android:weightSum="8"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/title"
android:textColor="@color/red"
android:textStyle="bold"
android:background="@color/white"
android:paddingBottom="@dimen/small"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/topic"
android:textColor="@color/red"
android:textStyle="bold"
android:background="@color/white"
android:gravity="center"
android:layout_weight="1"/>
<TextView
android:id="@+id/welcomescreen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/menu"
android:textColor="@color/red"
android:textStyle="bold"
android:background="@color/white"
android:gravity="center"
android:layout_weight="1"/>
<ListView
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"/>
</LinearLayout>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/androiddev"
android:layout_weight="1"
>
</ImageView>
</LinearLayout>
d. Main2Activity.java:
package com.example.practical34;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.util.Linkify;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
TextView tv;
ListView list;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
list=findViewById(R.id.menu);
tv=findViewById(R.id.welcomescreen);
tv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
startActivity(new Intent(Main2Activity.this,
MainActivity.class));
}
});
String[]
items=getResources().getStringArray(R.array.Options);
ArrayAdapter<String> adapt=new
ArrayAdapter<String>(this, R.layout.layout, items);
list.setAdapter(adapt);
list.setOnItemClickListener(new
AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent,
View view, int position, long id) {
tv=(TextView)view;
switch (position)
{
case 0: startActivity(new
Intent(Main2Activity.this, Main4Activity.class));
case 1:
String phone=tv.getText().toString();
phone="tel:"+phone;
// startActivity(new
Intent(Intent.ACTION_DIAL, Uri.parse(phone)));
Linkify.addLinks(tv,
Linkify.PHONE_NUMBERS);
break;
case 2:
Linkify.addLinks(tv,
Linkify.EMAIL_ADDRESSES);
break;
case 3: startActivity(new
Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.google.co.in")));
break;
case 4: startActivity(new
Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.tutorialspoint.com/android/")));
break;
}
});
}
}
e. Activity_main3.xml:
<?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:background="@color/colorPrimaryDark"
tools:context=".Main3Activity">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/android2">
</ImageView>
</LinearLayout>
f. Activity_main4.xml:
<?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=".Main4Activity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="306dp"
android:src="@drawable/grumpycat">
</ImageView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textColor="@color/red"
android:textSize="@dimen/large"
android:text="Rithwik Basrur">
</TextView>
</LinearLayout>
g. Layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Test"
android:textSize="10pt"
android:layout_margin="40dp"
android:textColor="@color/colorPrimaryDark"
android:textStyle="bold|italic"
android:gravity="center_horizontal"
>
</TextView>
h. Strings.xml:
<resources>
<string name="app_name">Practical3,4</string>
<string name="welcome">Welcome to</string>
<string name="Intro">Introduction to App Development</string>
<string name="prg">B.Tech Sem VIII</string>
<string name="topic">Android Program</string>
<string name="next">Click to continue....</string>
<string name="title">Mobile App Dev</string>
<string name="android">Android Programming</string>
<string name="menu">Main Menu</string>
<string name="back">Back</string>
<string-array name="Options">
<item>Rithwik Basrur</item>
<item>+919821230066</item>
<item>rithwik.basrur@gmail.com</item>
<item>Google Search</item>
<item>Android Tutorial</item>
</string-array>
</resources>
i. Colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#D81B60</color>
<color name="blue">#00A8FF</color>
<color name="yellow">#FFEA00</color>
<color name="red">#D30000</color>
<color name="white">#FFFFFF</color>
</resources>
j. Dimen.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="small">10dp</dimen>
<dimen name="medium">20dp</dimen>
<dimen name="large">30dp</dimen>
</resources>
6:
i. Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<GridLayout 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"
android:rowCount="7"
android:columnCount="3"
tools:context=".MainActivity"
android:background="@color/yellow"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_row="0"
android:layout_column="0"
android:layout_columnSpan="3"
android:layout_gravity="center_horizontal"
android:textSize="30dp"
android:textColor="@color/colorPrimaryDark"
android:text="Student Details" />
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Enter Roll No."
android:layout_column="0"
android:textSize="17dp"
android:layout_row="1"
/>
<EditText
android:id="@+id/textroll"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_row="1"
android:textSize="17dp"
android:layout_column="2"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Enter Name"
android:layout_column="0"
android:textSize="17dp"
android:layout_row="2"
/>
<EditText
android:id="@+id/textname"
android:layout_height="wrap_content"
android:layout_width="180dp"
android:layout_column="2"
android:layout_row="2"
android:textSize="17dp"
/>
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Enter Marks"
android:layout_column="0"
android:layout_row="3"
android:textSize="17dp"
/>
<EditText
android:id="@+id/textmarks"
android:layout_height="wrap_content"
android:layout_width="180dp"
android:layout_column="2"
android:layout_row="3"
android:textSize="17dp"
/>
<Button
android:id="@+id/buttonadd"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_column="1"
android:layout_row="4"
android:text="Add"
android:textSize="17dp"
android:layout_margin="10dp"
/>
<Button
android:id="@+id/delete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="4"
android:text="Delete"
android:layout_margin="10dp"
android:textSize="17dp"
/>
<Button
android:id="@+id/modify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="1"
android:layout_row="5"
android:textSize="17dp"
android:layout_margin="10dp"
android:text="Modify"
/>
<Button
android:id="@+id/view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_column="2"
android:layout_row="5"
android:text="View"
android:layout_margin="10dp"
android:textSize="17dp"
/>
<Button
android:id="@+id/viewall"
android:layout_width="208dp"
android:layout_height="wrap_content"
android:layout_row="6"
android:layout_column="1"
android:layout_columnSpan="2"
android:text="View All"
android:textSize="17dp"
/>
</GridLayout>
ii. MainActivity.java:
package com.example.practical6;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.AlertDialog.Builder;
btn_add.setOnClickListener(this);
btn_viewall.setOnClickListener(this);
btn_view.setOnClickListener(this);
btn_modify.setOnClickListener(this);
btn_delete.setOnClickListener(this);
} //End of onCreate
@Override
public void onClick(View v) {
if(v==btn_add)
{
if(txt_roll.getText().toString().trim().length()==0)
{
//Empty input not allowed
showMessage("Error", "Roll No. is missing");
}
else if (txt_marks.getText().toString().trim().length()==0)
{
showMessage("Error", "Marks are missing");
}
else if (txt_name.getText().toString().trim().length()==0)
{
showMessage("Error", "Name is missing");
}
else
{
db.execSQL("Insert into student values('"+
txt_roll.getText() + "','"+ txt_name.getText() + "','"+ txt_marks.getText()
+ "');");
if(v==btn_delete)
{
if (txt_roll.getText().toString().trim().length()==0)
{
showMessage("Error", "RollNo cannot be blank");
}
else
{
Cursor c=db.rawQuery("Select * from student where
rollno='"+txt_roll.getText()+"';",null);
if (c.getCount()!=0)
{
db.execSQL("delete from student where rollno='"+
txt_roll.getText() + "';");
showMessage("Success","Record Deleted");
}
else
{
showMessage("Error","Record does not exist");
}
}
clear();
} //btn_delete
if (v==btn_modify)
{
if(txt_roll.getText().toString().trim().length()==0)
{
//Empty input not allowed
showMessage("Error", "Roll No. is missing");
}
else if (txt_marks.getText().toString().trim().length()==0)
{
showMessage("Error", "Marks are missing");
}
else if (txt_name.getText().toString().trim().length()==0)
{
showMessage("Error", "Name is missing");
}
else
{
Cursor c=db.rawQuery("Select * from student where rollno='"
+ txt_roll.getText() + "';", null);
if(c.getCount()==0)
{
showMessage("Error","Record does not exist");
}
else
{
db.execSQL("update student set name='" +
txt_name.getText() + "',marks='" + txt_marks.getText() + "' where rollno='"
+ txt_roll.getText() + "';");
// update student set name,marks, where rollno;
showMessage("Success","Record Updated");
}
}
clear();
} //btn_modify
if(v==btn_view)
{
if (txt_roll.getText().toString().trim().length()==0)
{
showMessage("Error", "RollNo cannot be blank");
}
else
{
Cursor c=db.rawQuery("select * from student where rollno='"
+ txt_roll.getText() + "';",null);
if(c.getCount()==0)
{
showMessage("Error","Rollno does not exist");
}
else
{
c.moveToFirst();
txt_name.setText(c.getString(1));
txt_marks.setText(c.getString(2));
}
}
} //btn_view
if (v==btn_viewall)
{
Cursor c=db.rawQuery("select * from student;",null);
if(c.getCount()==0)
{
showMessage("Error","The table is empty");
}
else
{
StringBuffer buffer=new StringBuffer();
while(c.moveToNext())
{
buffer.append("RollNo: "+c.getString(0)+"\n");
buffer.append("Name: "+c.getString(1)+"\n");
buffer.append("Marks: "+c.getString(2)+"\n"+"\n");
}
showMessage("Student Details",buffer.toString());
}
}
} //end of onClick
} //End of MainActivity class
iii. Colors.xml:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#000000</color>
<color name="colorAccent">#D81B60</color>
<color name="yellow">#00A2FF</color>
</resources>