Practical 19
Practical 19
1). Write a program to create your own content provider to insert and access data
In android application.
Code :-
ACTIVITY_MAIN.XML
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 :-