I was created a simple rawQuery in my main activity but it's not working. Cursor is not working but my database is alredy in this PELE folder in External Storage. Please help me what is the problem
My helper class is:
public class Helper extends SQLiteOpenHelper{
private static final String LOGTAG="EXPLORECA";
private static final String DATABASE_NAME="Adatbazis.db";
private static final int DATABASE_VERSION=1;
private static final String FILE_DIR="PELE";
public static final String TABLE_TOURS="adattabla.db";
public static final String COLUMN_ID="userID";
public static final String COLUMN_NAME="username";
public Helper(Context context) {
super(context, Environment.getExternalStorageDirectory()
+ File.separator + FILE_DIR
+ File.separator + DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
Log.i(LOGTAG, "Az adattábla elkészült");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
And here is my main Activity. Cursor is not working but my database is alredy in this PELE folder in External Storage.
public class MainActivity extends AppCompatActivity {
SQLiteOpenHelper dbHelper;
SQLiteDatabase db;
Spinner helysegvalaszto, tagvalaszto, reszletvalaszto;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
helysegvalaszto();
}
public void helysegvalaszto(){
dbHelper= new Helper(this);
db=dbHelper.getReadableDatabase();
ArrayList<String> helysegek = new ArrayList<String>();
Cursor Chelyseg = db.rawQuery("select DISTINCT Helykod.h_kod, Helykod.h_nev from import1 JOIN Helykod on import1.helyseg=Helykod.h_kod", null);
Chelyseg.moveToFirst();
String hely = "";
while (!Chelyseg.isAfterLast()) {
hely = "" + Chelyseg.getString(Chelyseg.getColumnIndex("h_nev"));
helysegek.add(hely);
Chelyseg.moveToNext();
}
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(
this,
android.R.layout.simple_list_item_1,
helysegek);
helysegvalaszto.setAdapter(adapter1);
}
}
Aucun commentaire:
Enregistrer un commentaire