我需要执行一个查询要从多个表中检索数据,但我对如何一次完成所有操作感到困惑.
Books: _ISBN , BookTitle, Edition, Year, PublisherID, Pages, Rating
Categories: _CategoryID, Category
Categories_Books: _Categories_Category_ID, _Books_ISBN
Publishers: _Publisherid, Publisher
Writers: _WriterID, LastName
Writers_Books: _Writers_WriterID, _Books_ISBN
Run Code Online (Sandbox Code Playgroud)
Categories_Books而Writers_Books在中间表,以帮助我实现很多的表之间的多对多关系.
我需要一个具有多个连接的单个查询来选择:
我讨厌由简单的游标适配器创建的列表:
Cursor c = myDbHelper.rawQ(select);
startManagingCursor(c);
// the desired columns to be bound
String[] columns = new String[] { "Books.BookTitle",
"Publishers.Publisher" };
// the XML defined views which the data will be bound to
int[] to = new int[] { R.id.ISBN_entry, R.id.Title_entry };
// Getting results into our listview
try {
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(this,
R.layout.listlayout, c, columns, to);
this.setListAdapter(mAdapter);
} catch (Exception e) {
}
Run Code Online (Sandbox Code Playgroud)
列表涉及的布局是两个简单的文本视图.
我想要做的是创建一个监听器
@Override
protected void onListItemClick(ListView l, View v, int position, long id) …Run Code Online (Sandbox Code Playgroud) 很难说只是粘贴我的代码,希望有人会看到我失踪的东西:
Database.Java
package gr.peos;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import android.content.Context;
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteException;
import android.database.sqlite.SQLiteOpenHelper;
public class Database extends SQLiteOpenHelper{
//The Android's default system path of your application database.
private static String DB_PATH = "/data/data/gr.peos/databases/";
//Name of the Database to be created.
private static String DB_NAME = "BLib";
private SQLiteDatabase myDataBase;
private final Context myContext;
/**
* Constructor
* Takes and keeps a reference of the passed context in order to access to …Run Code Online (Sandbox Code Playgroud)