Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Android and SQLite :How to insert view update delete with image and list view Full source code
Description: I have developed this application using android Studio ,Java and SQLite. In this document, you will learn how to -create database and tablein sqlite using java -insert an image in android Studio using java and SQLite -update data -delete data ---Tested Full souce code with 100% working
Description: I have developed this application using android Studio ,Java and SQLite. In this document, you will learn how to -create database and tablein sqlite using java -insert an image in android Studio using java and SQLite -update data -delete data ---Tested Full souce code with 100% working
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
1|Page
Android SQLite How to insert view update delete with image and list view Full source code
AndroidManifest
...
0" encoding="utf-8"?>
...
imgefileinsqlitedatabase">
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme
...
MainActivity">
Hafiz Muhammad Umar Hayat
Page 1
2|Page
colors
...
0" encoding="utf-8"?>
Strings
...
Hafiz Muhammad Umar Hayat
Page 2
3|Page
activity_main
...
android
...
android
...
MainActivity">
android:textSize="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="100dp"
android:onClick="buttonClicked"
android:id="@+id/pic"
android:src="@mipmap/ic_launcher"
/>
android:layout_height="50dp"
android:id="@+id/txt1"
Hafiz Muhammad Umar Hayat
Page 3
4|Page
android:hint="Enter your first name"
android:layout_margin="10dp"/>
android:orientation="horizontal"
android:gravity="center"
android:layout_height="wrap_content">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="buttonClicked"
android:id="@+id/save"
android:text="Save"/>
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="buttonClicked"
android:id="@+id/display"
android:text="Display"/>
Hafiz Muhammad Umar Hayat
Page 4
5|Page
android:layout_height="match_parent">
android:layout_height="match_parent"
android:id="@+id/list1"/>
Hafiz Muhammad Umar Hayat
Page 5
6|Page
Listcontacts
...
0" encoding="utf-8"?>
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:id="@+id/txtViewer"
/>
android:layout_height="100dp"
android:id="@+id/imgView"/>
Hafiz Muhammad Umar Hayat
Page 6
7|Page
Contact
...
_fname = _fname;
this
...
_id = _id;
this
...
_img = _img;
}
public Contact() {
}
public int get_id() {
return _id;
}
public void set_id(int _id) {
this
...
_fname = _fname;
}
public byte[] get_img() {
return _img;
}
public void set_img(byte[] _img) {
this
...
java
import android
...
Context;
import android
...
Bitmap;
import android
...
BitmapFactory;
import android
...
LayoutInflater;
import android
...
View;
import android
...
ViewGroup;
import android
...
ArrayAdapter;
import android
...
ImageView;
import android
...
TextView;
import java
...
ArrayList;
public class dataAdapter extends ArrayAdapter
Context context;
ArrayList
public dataAdapter(Context context, ArrayList
super(context, R
...
listcontacts, contact);
this
...
mcontact=contact;
}
public class Holder{
Hafiz Muhammad Umar Hayat
Page 9
10 | P a g e
TextView nameFV;
ImageView pic;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
Contact data = getItem(position);
// Check if an existing view is being reused, otherwise inflate the view
Holder viewHolder; // view lookup cache stored in tag
if (convertView == null) {
viewHolder = new Holder();
LayoutInflater inflater = LayoutInflater
...
inflate(R
...
listcontacts, parent, false);
viewHolder
...
findViewById(R
...
txtViewer);
viewHolder
...
findViewById(R
...
imgView);
convertView
...
getTag();
Hafiz Muhammad Umar Hayat
Page 10
11 | P a g e
}
viewHolder
...
setText("First Name: "+data
...
pic
...
get_img()));
// Return the completed view to render on screen
return convertView;
}
//get bitmap image from byte array
private Bitmap convertToBitmap(byte[] b){
return BitmapFactory
...
length);
}
}
Hafiz Muhammad Umar Hayat
Page 11
12 | P a g e
DatabaseHandler
...
content
...
content
...
database
...
database
...
SQLiteDatabase;
import android
...
sqlite
...
util
...
util
...
execSQL(CREATE_TABLE_CONTACTS);
}
// Upgrading database
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db
...
getReadableDatabase();
ContentValues values=new ContentValues();
values
...
get_fname());
values
...
get_img() );
Hafiz Muhammad Umar Hayat
Page 13
14 | P a g e
db
...
close();
}
/**
*Getting All Contacts
**/
public List
List
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this
...
rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor
...
set_id(Integer
...
getString(0)));
contact
...
getString(1));
contact
...
getBlob(2));
Hafiz Muhammad Umar Hayat
Page 14
15 | P a g e
// Adding contact to list
contactList
...
moveToNext());
}
// return contact list
return contactList;
}
/**
*Updating single contact
**/
public int updateContact(Contact contact, int id) {
SQLiteDatabase db = this
...
put(KEY_FNAME, contact
...
put(KEY_POTO, contact
...
update(TABLE_CONTACTS, values, KEY_ID + " = ?",
new String[] { String
...
getWritableDatabase();
db
...
valueOf(Id) });
db
...
java
import androidx
...
app
...
core
...
ActivityCompat;
import android
...
content
...
content
...
PackageManager;
import android
...
Cursor;
import android
...
sqlite
...
graphics
...
graphics
...
os
...
os
...
view
...
widget
...
widget
...
widget
...
io
...
annotation
...
app
...
content
...
graphics
...
graphics
...
net
...
os
...
os
...
view
...
widget
...
widget
...
widget
...
widget
...
widget
...
io
...
util
...
onCreate(savedInstanceState);
setContentView(R
...
activity_main);
Hafiz Muhammad Umar Hayat
Page 18
19 | P a g e
//Instantiate database handler
db=new DatabaseHandler(this);
lv = (ListView) findViewById(R
...
list1);
pic= (ImageView) findViewById(R
...
pic);
fname=(EditText) findViewById(R
...
txt1);
}
public void buttonClicked(View v){
int id=v
...
id
...
getText()
...
trim()
...
makeText(getApplicationContext(),"Name edit text is empty, Enter name",
Toast
...
show();
} else{
addContact();
}
break;
case R
...
display:
Hafiz Muhammad Umar Hayat
Page 19
20 | P a g e
ShowRecords();
break;
case R
...
pic:
selectImage();
break;
}
}
public void selectImage(){
Intent photoPickerIntent = new Intent(Intent
...
setType("image/*");
startActivityForResult(photoPickerIntent, 2);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch(requestCode) {
case 2:
if(resultCode == RESULT_OK){
Uri choosenImage = data
...
setImageBitmap(bp);
}
}
}
Hafiz Muhammad Umar Hayat
Page 20
21 | P a g e
}
//COnvert and resize our image to 400dp for faster uploading our images to DB
protected Bitmap decodeUri(Uri selectedImage, int REQUIRED_SIZE) {
try {
// Decode image size
BitmapFactory
...
Options();
o
...
decodeStream(getContentResolver()
...
It should be the power of 2
...
outWidth, height_tmp = o
...
Options o2 = new BitmapFactory
...
inSampleSize = scale;
return
BitmapFactory
...
openInputStream(selectedImage), null,
o2);
}
catch (Exception e){
e
...
VERSION_CODES
...
compress(Bitmap
...
PNG, 0, bos);
return bos
...
getText()
...
addContacts(new Contact(f_name, photo));
Toast
...
LENGTH_LONG)
...
getAllContacts());
data=new dataAdapter(this, contacts);
lv
...
setOnItemClickListener(new AdapterView
...
get(position);
Toast
...
valueOf(dataModel
...
LENGTH_SHORT)
Title: Android and SQLite :How to insert view update delete with image and list view Full source code
Description: I have developed this application using android Studio ,Java and SQLite. In this document, you will learn how to -create database and tablein sqlite using java -insert an image in android Studio using java and SQLite -update data -delete data ---Tested Full souce code with 100% working
Description: I have developed this application using android Studio ,Java and SQLite. In this document, you will learn how to -create database and tablein sqlite using java -insert an image in android Studio using java and SQLite -update data -delete data ---Tested Full souce code with 100% working