问题描述
我在我的数据库中的两个表
Placetype和地点
placetype包括像resturaunt,旅馆,汽车旅馆等
所有placetypes的现在我要当resturaunt用户点击比如,他得到所有的returaunt列表,而不是所有的地方其他然后resturaunt。我无法做到这一点。请帮助...
这是我的code:
Database.java
包com.example.nearbyplaces;进口的java.util.ArrayList;
进口的java.util.List;进口android.content.ContentValues;
进口android.content.Context;
进口android.database.Cursor;
进口android.database.sqlite.SQLiteDatabase;
进口android.database.sqlite.SQLiteOpenHelper;
进口android.util.Log;公共类数据库处理器扩展SQLiteOpenHelper { 私有静态最后弦乐DB_NAME =nearby_place;
私有静态最终诠释db_version = 1; //表
私有静态最后弦乐table_placetypes =placetypes;
私有静态最后弦乐table_places =table_places; //列名
私有静态最后弦乐TYPE_ID =TYPE_ID;
私有静态最后弦乐TYPE_NAME =TYPE_NAME;
私有静态最后弦乐place_id =place_id;
私有静态最后弦乐PLACE_NAME =PLACE_NAME;
私有静态最后弦乐place_address =place_address;
私有静态最后弦乐place_contact =place_contact;
公共数据库处理器(上下文的背景下){
超(背景下,DB_NAME,空,db_version);
// TODO自动生成构造函数存根
} //创建表查询
字符串create_table_placetypes =CREATE TABLE IF NOT EXISTS+ table_placetypes +(
+ TYPE_ID +INTEGER PRIMARY KEY NOT NULL,+ TYPE_NAME +TEXT+); 字符串create_table_places =CREATE TABLE IF NOT EXISTS table_places(place_id INTEGER PRIMARY KEY NOT NULL,TEXT PLACE_NAME,place_address TEXT,place_contact TEXT,INTEGER TYPE_ID,外键(TYPE_ID)参考table_placetypes(TYPE_ID)); @覆盖
公共无效的onCreate(SQLiteDatabase DB){
// TODO自动生成方法存根 db.execSQL(create_table_placetypes); Log.d(创造,创建placetypes);
db.execSQL(create_table_places);
Log.d(创造,创造的地方);
}
@覆盖
公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页){
// TODO自动生成方法存根
db.execSQL(DROP TABLE IF EXISTS+ table_placetypes);
db.execSQL(DROP TABLE IF EXISTS+ table_places);
的onCreate(DB); }
//添加placetypes
无效addplacetypes(placetypes PT){ SQLiteDatabase分贝= getWritableDatabase();
ContentValues值=新ContentValues(); values.put(TYPE_NAME,pt.getTypename()); db.insert(table_placetypes,空,价值);
db.close(); } //获取单placetypes
placetypes getPlacetypes(INT ID){
SQLiteDatabase分贝= this.getReadableDatabase(); 光标光标= db.query(table_placetypes,新的String [] {TYPE_ID,
TYPE_NAME},TYPE_ID +=?,
新的String [] {将String.valueOf(ID)},NULL,NULL,NULL,NULL);
如果(指针!= NULL)
cursor.moveToFirst(); placetypes PT =新placetypes(的Integer.parseInt(cursor.getString(0)),
cursor.getString(1));
//返回接触
返回PT;
} //获取所有placetypes
公开名单< placetypes> getAllPlacetypes(){
清单< placetypes> placetypesList =新的ArrayList< placetypes>();
//选择所有查询
字符串selectQuery =SELECT * FROM+ table_placetypes; SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL); //通过所有行循环,并增加列表
如果(cursor.moveToFirst()){
做{
placetypes PT =新placetypes();
pt.setTypeid(的Integer.parseInt(cursor.getString(0)));
pt.setTypename(cursor.getString(1));
//字符串名称= cursor.getString(1); //MainActivity.ArrayofName.add(name);
//添加联系人名单
placetypesList.add(PT);
}而(cursor.moveToNext());
} //返回placetype名单
返回placetypesList;
} //获取placetypes计数
公众诠释getPlacetypesCount(){
字符串countQuery =SELECT * FROM+ table_placetypes;
SQLiteDatabase分贝= this.getReadableDatabase();
光标光标= db.rawQuery(countQuery,NULL);
cursor.close(); //返回计数
返回cursor.getCount();
} 公共无效addplaces(地方P){
SQLiteDatabase分贝= getWritableDatabase();
ContentValues值=新ContentValues();
values.put(PLACE_NAME,p.getPlace_name());
values.put(place_address,p.getPlace_address());
values.put(place_contact,p.getPlace_contact());
values.put(TYPE_ID,p.getT_id()); Log.d(类型ID中,将String.valueOf(p.getT_id()));
db.insert(table_places,空,价值);
db.close(); } 地方getPlaces(INT PID){ SQLiteDatabase分贝= getReadableDatabase();
光标光标= db.query(table_places,新的String [] {place_id,PLACE_NAME,place_address,place_contact,TYPE_ID},place_id +=?,新的String [] {将String.valueOf(PID)},NULL,NULL,NULL , 空值); 如果(指针!= NULL)
cursor.moveToFirst(); 地方P =新的地方(的Integer.parseInt(cursor.getString(0)),
的Integer.parseInt(cursor.getString(1)),
cursor.getString(2),
cursor.getString(3),
cursor.getString(4)
); cursor.close(); 回磷; } 公开名单<地方> getAllPlaces(字符串的typeName){ 清单<地方> placeList =新的ArrayList<地方>();
//字符串selectQuery =SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id = table_places.type_id;
//字符串selectQuery =SELECT * FROM table_places WHERE table_places.type_id =+ Integer.toString(typeid的);
//字符串selectQuery =SELECT * FROM table_places WHERE table_places.place_name =+的typeName +INNER JOIN placetypes ON placetypes.type_id = table_places.type_id;
//字符串selectQuery =SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id = table_places.type_id WHERE table_places.place_name =+的typeName +;
//字符串selectQuery =SELECT * FROM+ table_places;
字符串selectQuery =SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id = table_places.type_id WHERE placetypes.type_name ='+ +的typeName';
SQLiteDatabase分贝= this.getWritableDatabase();
光标光标= db.rawQuery(selectQuery,NULL);
如果(cursor.moveToFirst())
{
做{
则以P =新的地方();
/*p.setT_id(cursor.getColumnIndex(type_id));
p.setPlace_id(cursor.getColumnIndex(place_id));
p.setPlace_name(cursor.getColumnIndex(PLACE_NAME));
* /
p.setT_id(cursor.getInt(0));
p.setPlace_id(cursor.getInt(1));
p.setPlace_name(cursor.getString(2));
p.setPlace_address(cursor.getString(3));
p.setPlace_contact(cursor.getString(4)); / *字符串t_id = cursor.getString(4);
串p_name = cursor.getString(2);
串p_address = cursor.getString(3);
串p_contact = cursor.getString(1); * / placeList.add(P);
}而(cursor.moveToNext());
} cursor.close();
返回placeList;
} 公众诠释getPlaceCount(){ 字符串selectQuery =SELECT * FROM+ table_places;
SQLiteDatabase分贝= getReadableDatabase();
光标光标= db.rawQuery(create_table_places,NULL);
cursor.close(); 返回cursor.getCount();
}}
MainActivity2
包com.example.nearbyplaces;进口的java.util.ArrayList;
进口的java.util.List;
进口android.app.Activity;
进口android.content.Intent;
进口android.os.Bundle;
进口android.util.Log;
进口android.view.View;
进口android.widget.AdapterView;
进口android.widget.ArrayAdapter;
进口android.widget.ListView;
进口android.widget.TextView;
进口android.widget.Toast;
进口android.widget.AdapterView.OnItemClickListener;公共类MainActivity2延伸活动{ 私人的ListView ListView的;
公共静态的ArrayList<串GT; ArrayofName =新的ArrayList<串GT;();
@覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.activity_main);
意向检查= getIntent();
字符串x = check.getStringExtra(MainActivity.PLACETYPE);
Toast.makeText(getApplicationContext()中,x,Toast.LENGTH_SHORT).show(); 数据库处理器DB =新的数据库处理器(本);
如果(db.getAllPlaces(X).isEmpty())
{
/ **
* CRUD操作
* * /
//插入Places2
Log.d(插入,插入..);
db.addplaces(新的地方(必胜客,ABC,123,1));
//db.addplaces(new的地方(必胜客,NULL,NULL));
/ * db.addplacetypes(新placetypes(MALLS));
db.addplacetypes(新placetypes(加油站));
db.addplacetypes(新placetypes(HOTELS));
db.addplacetypes(新placetypes(汽车旅馆));
* /}
//读取所有的地方
Log.d(读,读所有的地方..); 如果(ArrayofName.isEmpty())
{
清单<地方>地方= db.getAllPlaces(X);
对于(地方号码:地方)
{
字符串日志=ID:+ p.getPlace_id()+,名称:+ p.getPlace_name()+,地址:+ p.getPlace_address()+联络电话:+ p.getPlace_contact() ;
//写作的地方登录
Log.d(姓名,日志);
Log.d(地址,日志);
Log.d(联系电话,日志); 的System.out.println(日志);
ArrayofName.add(p.getPlace_name());
// ArrayofName.add(p.getPlace_address());
// ArrayofName.add(p.getPlace_contact());
}
} ListView控件=(ListView控件)findViewById(R.id.listView1); ArrayAdapter<串GT;适配器=新ArrayAdapter<串GT;(这一点,
android.R.layout.simple_list_item_1,ArrayofName); listView.setAdapter(适配器); listView.setOnItemClickListener(新OnItemClickListener()
{
公共无效onItemClick(适配器视图<>母公司,视图V,INT位置,长的ID)
{
Toast.makeText(getApplicationContext(),((TextView的)ⅴ).getText(),Toast.LENGTH_SHORT).show();
//意图I =新意图(这一点,Activity2.class);
// startActivity(ⅰ);
//意向意图=新意图(MainActivity.this,Activity2.class);
// startActivity(意向);
}
}
);
}}
logcat的
19 10-11:34:31.160:D /阅读:(12694):读取所有placetypes ..
10-11 19:34:31.164:D /名称:(12694):ID:1,名称:RESTURAUNTS
10-11 19:34:31.164:我/的System.out(12694):ID:1,名称:RESTURAUNTS
10-11 19:34:31.164:D /名称:(12694):ID:2,产品名称:MALLS
10-11 19:34:31.164:我/的System.out(12694):ID:2,产品名称:MALLS
10-11 19:34:31.164:D /名称:(12694):ID:3,名称:加油站
10-11 19:34:31.164:我/的System.out(12694):ID:3,名称:加油站
10-11 19:34:31.164:D /名称:(12694):ID:4,名称:HOTELS
10-11 19:34:31.164:我/的System.out(12694):ID:4,名称:HOTELS
10-11 19:34:31.164:D /名称:(12694):ID:5,名称:汽车旅馆
10-11 19:34:31.164:我/的System.out(12694):ID:5,名称:汽车旅馆
10-11 19:34:31.230:D / libEGL(12694):加载/vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
10-11 19:34:31.234:D / libEGL(12694):加载/vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
10-11 19:34:31.246:D / libEGL(12694):加载/vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
10-11 19:34:31.300:D / OpenGLRenderer(12694):启用调试模式0
10-11 19:34:33.320:D /插入:(12694):插入..
10-11 19:34:33.320:D /类型ID(12694):1
10-11 19:34:33.355:D /阅读:(12694):读取所有的地方..
10-11 19:34:33.363:D /名称:(12694):ID:0,名称:ABC,地址:123CONTACT NO。 :1
10-11 19:34:33.363:D /地址:(12694):ID:0,名称:ABC,地址:123CONTACT NO。 :1
10-11 19:34:33.363:D /联系电话:(12694):ID:0,名称:ABC,地址:123CONTACT NO。 :1
10-11 19:34:33.363:我/的System.out(12694):ID:0,名称:ABC,地址:123CONTACT NO。 :1
10-11 19:34:50.090:D /插入:(12766):插入..
10-11 19:34:50.090:D /类型ID(12766):1
10-11 19:34:50.113:D /阅读:(12766):读取所有的地方..
10-11 19:36:08.488:D /插入:(12877):插入..
10-11 19:36:08.488:D /类型ID(12877):1
10-11 19:36:08.511:D /阅读:(12877):读取所有的地方..
您需要限制查询。参数添加到getAllPlaces:
公开名单<地方> getAllPlaces(字符串的typeName){
和您的查询字符串更改为:
字符串selectQuery =SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id = table_places.type_id WHERE placetypes.place_name ='+ +的typeName';
现在,无论你叫getAllPlaces,用类型名称称呼它:
如果(db.getAllPlaces(X).isEmpty())
...
清单<地方>地方= db.getAllPlaces(X);
编辑:
为输出的问题,我想你想要的是:
//字符串日志=ID:+ p.getPlace_id()+,名称:+ p.getPlace_name()+,地址:+ p.getPlace_address( )+联络电话:+ p.getPlace_contact();
//写作的地方登录
Log.d(测试,ID:+ p.getPlace_id());
Log.d(测试,名称:+ p.getPlace_name());
Log.d(测试,地址+ p.getPlace_address());
Log.d(测试,联络电话:+ p.getPlace_contact());
I have two tables in my database Placetype and Place
placetype consists of all the placetypes like resturaunt, hotel, motel etc
now i want when a user click on resturaunt for eg, he gets all the returaunt list and not all the places other then resturaunt. i am unable to do this. please help...
here is my code:
Database.java
package com.example.nearbyplaces;
import java.util.ArrayList;
import java.util.List;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;
public class DatabaseHandler extends SQLiteOpenHelper {
private static final String db_name = "nearby_place";
private static final int db_version = 1;
//tables
private static final String table_placetypes = "placetypes";
private static final String table_places = "table_places";
//column names
private static final String type_id = "type_id";
private static final String type_name = "type_name";
private static final String place_id = "place_id";
private static final String place_name = "place_name";
private static final String place_address = "place_address";
private static final String place_contact = "place_contact";
public DatabaseHandler(Context context) {
super(context, db_name, null, db_version);
// TODO Auto-generated constructor stub
}
// create table queries
String create_table_placetypes = "CREATE TABLE IF NOT EXISTS " + table_placetypes + "("
+ type_id + " INTEGER PRIMARY KEY NOT NULL," + type_name + " TEXT" + ")";
String create_table_places = "CREATE TABLE IF NOT EXISTS table_places (place_id INTEGER PRIMARY KEY NOT NULL, place_name TEXT, place_address TEXT, place_contact TEXT, type_id INTEGER, FOREIGN KEY (type_id) REFERENCES table_placetypes(type_id))";
@Override
public void onCreate(SQLiteDatabase db) {
// TODO Auto-generated method stub
db.execSQL(create_table_placetypes);
Log.d("creating", "placetypes created");
db.execSQL(create_table_places);
Log.d("creating", "places created");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// TODO Auto-generated method stub
db.execSQL("DROP TABLE IF EXISTS " + table_placetypes);
db.execSQL("DROP TABLE IF EXISTS " + table_places);
onCreate(db);
}
// add placetypes
void addplacetypes (placetypes pt) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(type_name, pt.getTypename());
db.insert(table_placetypes, null, values);
db.close();
}
// Getting single placetypes
placetypes getPlacetypes(int id) {
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(table_placetypes, new String[] {type_id,
type_name }, type_id + "=?",
new String[] { String.valueOf(id) }, null, null, null, null);
if (cursor != null)
cursor.moveToFirst();
placetypes pt = new placetypes(Integer.parseInt(cursor.getString(0)),
cursor.getString(1));
// return contact
return pt;
}
// Getting All placetypes
public List<placetypes> getAllPlacetypes() {
List<placetypes> placetypesList = new ArrayList<placetypes>();
// Select All Query
String selectQuery = "SELECT * FROM " + table_placetypes;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
placetypes pt = new placetypes();
pt.setTypeid(Integer.parseInt(cursor.getString(0)));
pt.setTypename(cursor.getString(1));
//String name = cursor.getString(1);
//MainActivity.ArrayofName.add(name);
// Adding contact to list
placetypesList.add(pt);
} while (cursor.moveToNext());
}
// return placetype list
return placetypesList;
}
// Getting placetypes Count
public int getPlacetypesCount() {
String countQuery = "SELECT * FROM " + table_placetypes;
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(countQuery, null);
cursor.close();
// return count
return cursor.getCount();
}
public void addplaces(places p) {
SQLiteDatabase db = getWritableDatabase();
ContentValues values = new ContentValues();
values.put(place_name, p.getPlace_name());
values.put(place_address, p.getPlace_address());
values.put(place_contact, p.getPlace_contact());
values.put(type_id, p.getT_id());
Log.d("Type ID", String.valueOf(p.getT_id()));
db.insert(table_places, null, values);
db.close();
}
places getPlaces(int pid) {
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(table_places, new String[] {place_id, place_name, place_address, place_contact,type_id}, place_id + "=?", new String[] { String.valueOf(pid) } , null, null, null, null);
if(cursor != null)
cursor.moveToFirst();
places p = new places(Integer.parseInt(cursor.getString(0)),
Integer.parseInt(cursor.getString(1)),
cursor.getString(2),
cursor.getString(3),
cursor.getString(4)
);
cursor.close();
return p;
}
public List<places> getAllPlaces(String typeName) {
List<places> placeList = new ArrayList<places>();
//String selectQuery = "SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id=table_places.type_id ";
//String selectQuery = "SELECT * FROM table_places WHERE table_places.type_id="+Integer.toString(typeid);
//String selectQuery ="SELECT * FROM table_places WHERE table_places.place_name = " +typeName+ "INNER JOIN placetypes ON placetypes.type_id = table_places.type_id";
//String selectQuery = "SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id = table_places.type_id WHERE table_places.place_name = " + typeName + "";
//String selectQuery = "SELECT * FROM " +table_places;
String selectQuery ="SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id=table_places.type_id WHERE placetypes.type_name='"+typeName+"'";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
if(cursor.moveToFirst() )
{
do{
places p = new places();
/*p.setT_id(cursor.getColumnIndex(type_id));
p.setPlace_id(cursor.getColumnIndex(place_id));
p.setPlace_name(cursor.getColumnIndex(place_name));
*/
p.setT_id(cursor.getInt(0));
p.setPlace_id(cursor.getInt(1));
p.setPlace_name(cursor.getString(2));
p.setPlace_address(cursor.getString(3));
p.setPlace_contact(cursor.getString(4));
/*String t_id = cursor.getString(4);
String p_name = cursor.getString(2);
String p_address = cursor.getString(3);
String p_contact = cursor.getString(1);*/
placeList.add(p);
}while(cursor.moveToNext());
}
cursor.close();
return placeList;
}
public int getPlaceCount () {
String selectQuery = "SELECT * FROM " +table_places;
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.rawQuery(create_table_places, null);
cursor.close();
return cursor.getCount();
}
}
MainActivity2
package com.example.nearbyplaces;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class MainActivity2 extends Activity {
private ListView listView;
public static ArrayList<String> ArrayofName = new ArrayList<String>();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent check = getIntent();
String x = check.getStringExtra(MainActivity.PLACETYPE);
Toast.makeText(getApplicationContext(), x, Toast.LENGTH_SHORT).show();
DatabaseHandler db = new DatabaseHandler(this);
if(db.getAllPlaces(x).isEmpty())
{
/**
* CRUD Operations
* */
// Inserting Places2
Log.d("Insert: ", "Inserting ..");
db.addplaces(new places("Pizza Hut", "abc", "123",1));
//db.addplaces(new places("Pizza Hut",null,null));
/* db.addplacetypes(new placetypes("MALLS"));
db.addplacetypes(new placetypes("GAS STATIONS"));
db.addplacetypes(new placetypes("HOTELS"));
db.addplacetypes(new placetypes("MOTELS"));
*/}
// Reading all Places
Log.d("Reading: ", "Reading all places..");
if(ArrayofName.isEmpty())
{
List<places> places = db.getAllPlaces(x);
for (places p : places)
{
String log = "Id: "+p.getPlace_id() +" ,Name: " + p.getPlace_name() +" ,ADDRESS: " + p.getPlace_address() +"CONTACT NO. : " +p.getPlace_contact();
//Writing Places to log
Log.d("Name: ", log);
Log.d("ADDRESS: ", log);
Log.d("CONTACT NO : ", log);
System.out.println(log);
ArrayofName.add(p.getPlace_name());
// ArrayofName.add(p.getPlace_address());
// ArrayofName.add(p.getPlace_contact());
}
}
listView = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, ArrayofName);
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(getApplicationContext(), ((TextView) v).getText(), Toast.LENGTH_SHORT).show();
// Intent i = new Intent(this,Activity2.class);
// startActivity(i);
// Intent intent = new Intent(MainActivity.this, Activity2.class);
// startActivity(intent);
}
}
);
}
}
Logcat
10-11 19:34:31.160: D/Reading:(12694): Reading all placetypes..
10-11 19:34:31.164: D/Name:(12694): Id: 1 ,Name: RESTURAUNTS
10-11 19:34:31.164: I/System.out(12694): Id: 1 ,Name: RESTURAUNTS
10-11 19:34:31.164: D/Name:(12694): Id: 2 ,Name: MALLS
10-11 19:34:31.164: I/System.out(12694): Id: 2 ,Name: MALLS
10-11 19:34:31.164: D/Name:(12694): Id: 3 ,Name: GAS STATIONS
10-11 19:34:31.164: I/System.out(12694): Id: 3 ,Name: GAS STATIONS
10-11 19:34:31.164: D/Name:(12694): Id: 4 ,Name: HOTELS
10-11 19:34:31.164: I/System.out(12694): Id: 4 ,Name: HOTELS
10-11 19:34:31.164: D/Name:(12694): Id: 5 ,Name: MOTELS
10-11 19:34:31.164: I/System.out(12694): Id: 5 ,Name: MOTELS
10-11 19:34:31.230: D/libEGL(12694): loaded /vendor/lib/egl/libEGL_POWERVR_SGX540_120.so
10-11 19:34:31.234: D/libEGL(12694): loaded /vendor/lib/egl/libGLESv1_CM_POWERVR_SGX540_120.so
10-11 19:34:31.246: D/libEGL(12694): loaded /vendor/lib/egl/libGLESv2_POWERVR_SGX540_120.so
10-11 19:34:31.300: D/OpenGLRenderer(12694): Enabling debug mode 0
10-11 19:34:33.320: D/Insert:(12694): Inserting ..
10-11 19:34:33.320: D/Type ID(12694): 1
10-11 19:34:33.355: D/Reading:(12694): Reading all places..
10-11 19:34:33.363: D/Name:(12694): Id: 0 ,Name: abc ,ADDRESS: 123CONTACT NO. : 1
10-11 19:34:33.363: D/ADDRESS:(12694): Id: 0 ,Name: abc ,ADDRESS: 123CONTACT NO. : 1
10-11 19:34:33.363: D/CONTACT NO :(12694): Id: 0 ,Name: abc ,ADDRESS: 123CONTACT NO. : 1
10-11 19:34:33.363: I/System.out(12694): Id: 0 ,Name: abc ,ADDRESS: 123CONTACT NO. : 1
10-11 19:34:50.090: D/Insert:(12766): Inserting ..
10-11 19:34:50.090: D/Type ID(12766): 1
10-11 19:34:50.113: D/Reading:(12766): Reading all places..
10-11 19:36:08.488: D/Insert:(12877): Inserting ..
10-11 19:36:08.488: D/Type ID(12877): 1
10-11 19:36:08.511: D/Reading:(12877): Reading all places..
You need to limit your query. Add a parameter to getAllPlaces:
public List<places> getAllPlaces(String typeName) {
And change your query string to:
String selectQuery ="SELECT * FROM table_places INNER JOIN placetypes ON placetypes.type_id=table_places.type_id WHERE placetypes.place_name='"+typeName+"'";
Now wherever you call getAllPlaces, call it with the type name:
if(db.getAllPlaces(x).isEmpty())
...
List<places> places = db.getAllPlaces(x);
EDIT:For your output issue, I think what you want is:
//String log = "Id: "+p.getPlace_id() +" ,Name: " + p.getPlace_name() +" ,ADDRESS: " + p.getPlace_address() +"CONTACT NO. : " +p.getPlace_contact();
//Writing Places to log
Log.d("Test", "Id: "+p.getPlace_id());
Log.d("Test", "Name: "+p.getPlace_name());
Log.d("Test", "Address: "+p.getPlace_address());
Log.d("Test", "Contact No.: "+p.getPlace_contact());
这篇关于如何从数据库中获取在列表视图特定项目的的onclick具体名单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!