0% found this document useful (0 votes)
28 views4 pages

Practical 19

The document outlines a mobile application development exercise by Shivam Sainath Korpakwad, focusing on creating a content provider for accessing contact data in an Android app. It includes XML layout files for the main activity and a list item, as well as Java code for querying and displaying contacts using a SimpleCursorAdapter. Additionally, there is a second exercise mentioned that involves centering Name, Age, and Mobile Number on the display screen using Absolute layout.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

Practical 19

The document outlines a mobile application development exercise by Shivam Sainath Korpakwad, focusing on creating a content provider for accessing contact data in an Android app. It includes XML layout files for the main activity and a list item, as well as Java code for querying and displaying contacts using a SimpleCursorAdapter. Additionally, there is a second exercise mentioned that involves centering Name, Age, and Mobile Number on the display screen using Absolute layout.

Uploaded by

sainathkorpakwad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Subject :- Mobile Application Development Subject Code :- 22617

Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24


Exercise :-

1). Write a program to create your own content provider to insert and access data
In android application.
Code :-
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:id="@+id/idRLLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<!--Creating a list view on below line-->
<ListView android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>

<?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="wrap_content"
android:layout_margin="3dp"
android:orientation="vertical">
<!-- on below line creating a text view for contact name-->
<TextView
android:id="@+id/idTVContactName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="Contact Name"
android:textColor="@color/black"
android:textSize="18sp"
android:textStyle="bold" />
<!-- on below line creating a text view for contact number -->
<TextView
android:id="@+id/idTVContactNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp"
android:text="Number"
android:textColor="@color/black"
android:textSize="16sp" /
</LinearLayout>

MAINACTIVITY.JAVA

package com.example.androidjavaapp;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity
{
// on below line creating a variable for list view.
private ListView contactsLV;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// on below line we are initializing our variables.
contactsLV = findViewById(R.id.listView);
// create cursor and querying the data on below line
Cursor cursor =getContentResolver().query
(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
// on below line calling method to manage the cursor.
startManagingCursor(cursor);
// on below line getting the data from contacts
String[] data = {ContactsContract.CommonDataKinds.Phone.NUMBER,
ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME,
ContactsContract.CommonDataKinds.Phone._ID};
// on below line specifying id to which we have to set the data.
int[] to = {R.id.idTVContactNumber, R.id.idTVContactName};
// on below line creating and initializing simple cursor adapter and passing the layout file
which we have to display.
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contacts_list_item,
cursor, data, to);
// on below line setting adapter to our list view.
contactsLV.setAdapter(adapter);
// on below line setting choice mode for list view.
contactsLV.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
}
}

Output :-
Subject :- Mobile Application Developmen Subject Code :- 22617
Name :- Shivam Sainath Korpakwad Batch :- CO 6 IA Roll No. 24

Exercise :-

2). Write a program to place Name, Age and Mobile Number centrally on the display
screen using Absolute layout.

Code :-

Output :-

You might also like