将图像存储在android中的数据库中并在列表中进行检索 [英] store images in database in android and retrive in list

查看:65
本文介绍了将图像存储在android中的数据库中并在列表中进行检索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package handler;

import java.util.ArrayList;

import property.property;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Property;

public class handler extends SQLiteOpenHelper
{

	static String Database_Name="rajkot_tourism.db";
	String Table_Name1="cat_tbl";
	String Cat_ID="cat_id";
	String Cat_Name="cat_name";
	String Area_ID="area_id";
	String Area_Name="erea_name";
	String Table_Name2="area_tbl";
	String Table_Name3="place_tbl";
	int idc;
	int ida;
	
	
	public handler(Context context) 
	{
		super(context,Database_Name,null,1);
		
	}

	@Override
	public void onCreate(SQLiteDatabase db) 
	{
	
		db.execSQL("CREATE TABLE cat_tbl(cat_id INTEGER PRIMARY KEY AUTOINCREMENT,cat_name TEXT)");
		db.execSQL("INSERT INTO cat_tbl(cat_name)VALUES('Attraction'),('Hotels'),('Restaurants'),('Shopping'),('Temples')");
		db.execSQL("CREATE TABLE area_tbl(area_id INTEGER PRIMARY KEY AUTOINCREMENT,area_name TEXT)");
		db.execSQL("INSERT INTO area_tbl(area_name)VALUES('Near Bus Stand'),('Yagnik Road'),('Limada Chowk'),('Kalawad Road'),('University Road'),('150 Ring Road'),('Other')");
		db.execSQL("CREATE TABLE place_tbl(place_id INTEGER PRIMARY KEY AUTOINCREMENT,place_name TEXT,place_address TEXT,place_image TEXT,place_desc TEXT,place_phno INTEGER,place_web TEXT,cat_id INTEGER REFERENCES cat_tbl(cat_id),area_id INTEGER REFERENCES area_tbl(area_id),place_latitude double,place_longitude double)");
		
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Confort INN Legacy','Panchnath Rd, Rajkot, Gujarat 360001','@drawable/confort_legacy','Comfort inn Legacy create hotel products that offer the highest standards and sense of value for money to our guests. Moreover, we have been providing the highest standard of customer satisfaction from all the brand segments of the hotel industry.Hotel Comfort INN Legacy,Rajkot continues to excels through innovative hospitality solutions.It has pioneered unique food and beverage concepts. AMBROSIA Multicuisine restaurant unanimously hailed as some of the finest Restaurant in the country.','0281 301 8555','http://hotelcomfortinnlegacy.com/','2','3','22.296055','70.798691')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('The Imperial Palace','Dr. Yagnik Road, Rajkot, India','@drawable/imperial_palace','The Imperial Palace hotel Rajkot is a masterpiece of simplicity,comfort and elegance, offering the ultimate in luxury,with the most spacious rooms among Rajkot hotels. Each one of the hotels opulent guest rooms is comfortable and stylish and equipped with advanced technology for the convenience of hotel guests - underlined, of course, by the extremely professional and sincere service by the Imperial staff which makes it stand out from other Rajkot hotels','0281 2480000','http://www.theimperialpalace.biz/','2','2','22.29523','70.7908')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Silver Palace','Yagnik Road Corner, Near Malaviya Petrol Pump, Rajkot','@drawable/silver_palace','Hotel Silver Palace, among the premier business hotels in Rajkot,the economic capital of Saurashtra is characterised by the traditional Kathiawari hospitality. Located in the heart of the city, in the vicinity of the exclusive mercantile & residential area of Rajkot.Silver Palace provides easy access to the airport and railway station which are just 3 kms away.Modern facilities with the finest hospitality makes it the ideal choice amongst hotels in Rajkot for businessmen and tourist.','0281 2480008','www.hotelsilverpalace.com','2','1','22.3038945','70.80215989')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Khirasara Palace','Kalawad Road, Nr. Metoda G.I.D.C., At : Khirsara (Ranmalji), Rajkot (Gujarat) India','@drawable/khirasara_palace','Situated 14 kms away from the bustling city of Rajkot, on Kalawad road-experience serenity, peace & clean fresh breeze, whilst being surrounded by the rich heritage, history & royal comfort within this grand monumental property spread over 7 acres.The majestic monument of Khirasara, which has witnessed the rich heritage and culture of the glorious past of Kathiawar,and has borne the brunt of centuries of history,now stands in its fullest splendour and glory, in the resplendent present.','02827 288444','http://www.khirasarapalace.in','2','4','22.2391534',' 70.65271129999')");
		db.execSQL("INSERT INTO place_tbl(place_name,place_address,place_image,place_desc,place_phno,place_web,cat_id,area_id,place_latitude,place_longitude)VALUES('Pradhyuman Lords Inn','Everest park, near Love Mandir Kalawad Road, Rajkot - 360005','@drawable/pradhyuman_lords','Pradhyuman Lords Inn is a contemporary designed business hotel situated at Kalawad Road.The hotel is ideally located at few minutes drive from the Rajkot railway station & the Airport.The hotel is created keeping in mind utmost guest comfort having 68 well furnished rooms.With latest amenities like Mini Bar, Snack basket in all Rooms & 24hrs Room Service,Wi-Fi Connectivity, Direct Dialing Facility, Electronic Vault & LCD TV, In house Laundry & Valet Service,Doctor on Call, Travel Desk, Business Center','0281 2562880','www.lordshotels.com','2','4','22.2726111','70.7581584')");
	}
	
	public ArrayList<property> display_cat()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query("cat_tbl", null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setCat_id(c.getInt(0));
			p.setCat_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public void image()
	{

	}
	public ArrayList<property> display_area()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query("area_tbl", null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setArea_id(c.getInt(0));
			p.setArea_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public property searchbyid(int id)
	{
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name1, null, Cat_ID+"="+id, null, null, null, null);
		
		
		property p=new property();
		
		while(c.moveToNext())
		{
			p.setCat_name(c.getString(1));
		}
		return p;
		
	}
	
	public property searchbyidarea(int id)
	{
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name2, null, Area_ID+ "="+ id, null, null, null, null);
		property p=new property();
		
		while(c.moveToNext())
		{
			p.setArea_name(c.getString(1));
		}
		return p;
		
	}
	public ArrayList<property> showplaceid(int idc,int ida)
	{
		SQLiteDatabase sd=getReadableDatabase();
		//String query=("select * from place_tbl where Cat_ID=idc AND Area_ID =ida");
		//Cursor c=sd.rawQuery(query, null);
		Cursor c=sd.query(Table_Name3,null,Cat_ID+"="+idc+" AND " +Area_ID+"="+ida,null,null,null, null);
		
		ArrayList<property> ar=new ArrayList<property>();
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setPlace_name(c.getString(1));
			ar.add(p);
		}
		sd.close();
		return ar;
		
	}
	
	public ArrayList<property> display_place()
	{
		ArrayList<property> ar=new ArrayList<property>();
		SQLiteDatabase sd=getReadableDatabase();
		Cursor c=sd.query(Table_Name3, null, null, null, null, null, null);
		
		property p;
		while(c.moveToNext())
		{
			p=new property();
			p.setPlace_address(c.getString(0));
			p.setPlace_id(c.getInt(1));
			p.setPlace_name(c.getString(2));
			p.setPlace_image(c.getString(3));
			p.setPlace_desc(c.getString(4));
			p.setPlace_phno(c.getInt(5));
			p.setPlace_web(c.getString(5));
			p.setPlace_latitude(c.getDouble(6));
			p.setPlace_longitude(c.getDouble(7));
			ar.add(p);
		}
		sd.close();
		return ar;
	}
	

	@Override
	public void onUpgrade(SQLiteDatabase db, int arg1, int arg2) {
		// TODO Auto-generated method stub
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name1);
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name2);
        db.execSQL("DROP TABLE IF EXISTS " + Table_Name3);



	}

}

推荐答案

有两种方法可以处理这种情况:



1.根本不将图像保存在数据库中。而是将图像保存在持久性存储器中的某个位置,如隐藏文件夹中的SDCard。并访问图像。



2.将图像保存为DB中的字节数组。在从DB读取字节数组数据后创建图像并在屏幕上显示。
There are two ways to handle this situation:

1. Not to save the image in the DB at all. Instead save the image somewhere on the persistent memory like SDCard in hidden folder. And access the image.

2. Save the image as byte array in the DB. And create the image after reading the byte array data from DB and show it on the screen.


这篇关于将图像存储在android中的数据库中并在列表中进行检索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆