Mad Output
Mad Output
Mad Output
EXPERIMENT NO.1
INSTALLING AND RUNNING APPLICATIONS ON ANDROID STUDIO
SOURCE CODE :
package com.example.helloworldapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
@Override
protected void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Xml code :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:padding="@dimen/padding_medium"
android:text="@string/hello_world"
tools:context=".MainActivity" />
EXPERIMENT NO.3. Create an application that takes the name from a text box and shows hello
message along with the name entered in text box, when the user clicks the OK button.
package com.example.akshay.mrcet;
import android.os.Bundle; import
android.support.v7.app.AppCompatActivity;
import android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.TextView;
@Override
public void onClick(View v) {
String name = editName.getText().toString();
String password = editPassword.getText().toString();
result.setText("Name:\t" + name + "\nPassword:\t" + password );
}
});
/*
Reset Button
*/
buttonReset.setOnClickListener(new View.OnClickListener() {
@Override public
void onClick(View v)
{ editName.setText("");
editPassword.setText("");
result.setText("");
editName.requestFocus();
}
});
}
}
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:layout_width="match_parent"
android:layout_height="match_parent" android:background="#FFFF8D"
tools:context="com.example.akshay.mrcet.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp" />
<TextView android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="PASSWORD"
android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView"
android:layout_alignStart="@+id/textView" />
<EditText android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword
" />
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" android:hint="Enter
Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="SUBMIT" />
<Button
android:id="@+id/buttonReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RESET"
android:layout_alignBaseline="@+id/buttonSubmit"
android:layout_alignBottom="@+id/buttonSubmit"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="tru
e"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp" />
</RelativeLayout>
EXPERIMENT NO.4. Create a screen that has input boxes for User Name, Password, Address,
Gender(radio buttons for male and female), Age (numeric) and a Submit button. On clicking the
submit button, print all the data below the Submit Button (use any layout)
package com.example.nkredy.mrcet;
@Override
public void onClick(View v) {
String name = editName.getText().toString();
String password =
editPassword.getText().toString(); String
address= editAddress.getText().toString(); int selectedId =
radioGenderGroup.getCheckedRadioButtonId();
}
});
}
}
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:layout_width="match_parent"
android:layout_height="match_parent" android:background="#FFFF8D"
tools:context="com.example.akshay.mrcet.MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="NAME"
android:textSize="20sp"
android:layout_margin="20dp" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="PASSWORD"
android:layout_marginTop="38dp"
android:layout_below="@+id/textView"
android:layout_alignLeft="@+id/textView
"
android:layout_alignStart="@+id/textVie
w" />
<EditText android:id="@+id/editName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:hint="Enter Name"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="@+id/editPassword"
android:layout_alignStart="@+id/editPassword" />
<EditText
android:id="@+id/editPassword"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10" android:hint="Enter
Password"
android:inputType="textPassword"
android:layout_alignBottom="@+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<EditText
android:id="@+id/editAddress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<EditText android:id="@+id/editAge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="18dp"
android:layout_marginEnd="18dp" />
<RadioGroup
android:id="@+id/radioGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_male"
android:checked="true" />
<RadioButton
android:id="@+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/radio_female" />
</RadioGroup>
<Button
android:id="@+id/buttonSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/textView2"
android:layout_marginTop="20dp"
android:text="SUBMIT" />
<TextView android:id="@+id/tvResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="143dp"
android:textSize="30sp" /></RelativeLayout>
EXPERIMENT NO.5.Design an android application to create page using Intent and one Button and
pass the Values from one Activity to second Activity.
Java File
package com.example.transferofdata;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import
android.view.View.OnClickListener;
import android.widget.Button; import
android.widget.EditText; public class
MainActivity extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final EditText et=(EditText)findViewById(R.id.editText1);
final EditText
et1=(EditText)findViewById(R.id.editText2); Button
send=(Button)findViewById(R.id.button1);
send.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View arg0)
{
String s=et.getText().toString();
String s1=et1.getText().toString();
Intent it=new Intent(MainActivity.this,Second.class);
it.putExtra("uname", s);
it.putExtra("pwd", s1);
startActivity(it);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
SecondActivity.java package
com.example.transferofdata;
import android.os.Bundle; import
android.app.Activity; import
android.view.Menu; import
android.widget.TextView; public
class Second extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_second);
TextView tv=(TextView)findViewById(R.id.textView1);
TextView tv1=(TextView)findViewById(R.id.textView2);
tv.setText(getIntent().getExtras().getString("uname"));
tv1.setText(getIntent().getExtras().getString("pwd"));
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
getMenuInflater().inflate(R.menu.second, menu);
return true;
}
}
MainActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="78dp"
android:layout_marginTop="154dp"
android:text="send" />
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignRight="@+id/button1"
android:layout_marginTop="18dp"
android:ems="10" ><requestFocus /></EditText>
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="@+id/button1"
android:layout_below="@+id/editText1"
android:layout_marginTop="37dp"
android:ems="10"
android:inputType="textPassword" /></RelativeLayout>
SecondActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".Second" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="42dp"
android:layout_marginTop="70dp"
android:text="uname" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:layout_marginLeft="15dp"
android:layout_marginTop="37dp" android:text="password" />
</RelativeLayout>
OUTPUT:
EXPERIMENT NO.6.Design an android application Send SMS using Intent
MainActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="54dp"
android:layout_marginTop="166dp"
android:text="send" />
</RelativeLayout>
OUTPUT:
7..Create an android application using Fragments
activity_main.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="fill_parent" android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">
<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment
1" android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment
2" android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"
/>
</LinearLayout>
fragment_fragment1.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F5F5DC"
tools:context="example.javatpoint.com.fragmentexample.Fragment1">
</FrameLayout>
File: fragment_fragment2.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0FFFF"
tools:context="example.javatpoint.com.fragmentexample.Fragment2">
</FrameLayout>
MainActivity class
File: MainActivity.java
package example.javatpoint.com.fragmentexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
@Override
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{ // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
}
File: Fragment2.java
package example.javatpoint.com.fragmentexample;
@Override
public void onCreate(Bundle savedInstanceState)
{ super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{ // Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment2, container, false);
}
}
Output:
MainActivity.xml
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<RadioGroup
android:id="@+id/myRadioGroup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="@+id/textView1"
android:layout_marginLeft="27dp"
android:layout_marginTop="28dp" >
<RadioButton
android:id="@+id/sound"
android:layout_width="wrap_content
"
android:layout_height="wrap_conten
t" android:checked="true"
android:text="Sound" />
<RadioButton
android:id="@+id/vibrate"
android:layout_width="wrap_content
"
android:layout_height="wrap_conten
t" android:text="Vibration" />
<RadioButton
android:id="@+id/silent"
android:layout_width="wrap_content
"
android:layout_height="wrap_conten
t" android:text="Silent" />
</RadioGroup> <TextView android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:text="Choose
one of the following modes"
android:textAppearance="?android:attr/textAppearanceLarg
e" />
<Button android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/myRadioGro
up"
android:layout_below="@+id/myRadioGroup"
android:layout_marginLeft="42dp"
android:layout_marginTop="53dp"
android:text="choose" />
</RelativeLayout>
OUTPUT:
9. Design an android application for menu.
MainActivity.xml
<RelativeLayout
xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
</RelativeLayout>
SecondActivity.xml
OUTPUT:
10 Create a user registration application that stores the user details in a database table.
DbHandler.java
package com.tutlane.sqliteexample;
import
android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import
android.database.sqlite.SQLiteDatabase;
import
android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList; import
java.util.HashMap;
/**
* Created by tutlane on 06-01-2018.
*/
}
return userList;
}
// Get User Details based on userid
public ArrayList<HashMap<String, String>> GetUserByUserId(int userid){
SQLiteDatabase db = this.getWritableDatabase();
ArrayList<HashMap<String, String>> userList = new ArrayList<>();
String query = "SELECT name, location, designation FROM "+ TABLE_Users;
Cursor cursor = db.query(TABLE_Users, new String[]{KEY_NAME, KEY_LOC, KEY_DESG},
KEY_ID+
"=?",new String[]{String.valueOf(userid)},null, null, null,
null); if (cursor.moveToNext()){
HashMap<String,String> user = new HashMap<>();
user.put("name",cursor.getString(cursor.getColumnIndex(KEY_NAME)));
user.put("designation",cursor.getString(cursor.getColumnIndex(KEY_DESG)));
user.put("location",cursor.getString(cursor.getColumnIndex(KEY_LOC)));
userList.add(user);
}
return userList;
}
// Delete User Details
public void DeleteUser(int userid){
SQLiteDatabase db = this.getWritableDatabase();
db.delete(TABLE_Users, KEY_ID+" = ?",new String[]{String.valueOf(userid)});
db.close();
}
// Update User Details
public int UpdateUserDetails(String location, String designation, int id){
SQLiteDatabase db =
this.getWritableDatabase(); ContentValues
cVals = new ContentValues();
cVals.put(KEY_LOC, location);
cVals.put(KEY_DESG, designation);
int count = db.update(TABLE_Users, cVals, KEY_ID+" = ?",new
String[]{String.valueOf(id)}); return count;
}
}
If you observe above code, we implemented all SQLite Database related activities to perform
CRUD operations in android application.
Now open activity_main.xml file from \res\layout folder path and write the code like as shown
below.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:text="Name" />
<EditText
android:id="@+id/txtName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10"/>
<TextView
android:id="@+id/secTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Location"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<TextView
android:id="@+id/thirdTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Designation"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/txtDesignation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Save" />
</LinearLayout>
details.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical" >
<ListView
android:id="@+id/user_list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:dividerHeight="1dp" />
<Button
android:id="@+id/btnBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="Back" />
</LinearLayout>
list_row.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:padding="5dip" >
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textStyle="bold"
android:textSize="17dp" />
<TextView
android:id="@+id/designation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_marginTop="7dp"
android:textColor="#343434"
android:textSize="14dp" />
<TextView
android:id="@+id/location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/designation"
android:layout_alignBottom="@+id/designation"
android:layout_alignParentRight="true"
android:textColor="#343434"
android:textSize="14dp" />
</RelativeLayout>
MainActivity.java
package com.tutlane.sqliteexample;
import android.content.Intent;
import
android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import
android.view.View; import
android.widget.Button; import
android.widget.EditText; import
android.widget.Toast;