0
I don’t know how to send one select made in my Databasehelper class and send it to a public class, then from that make my code work normally.
My Databasehelper class and at the end select:
class AddressBookDatabaseHelper extends SQLiteOpenHelper {
private static final String DATABASE_NAME = "Forca.db";
private static final int DATABASE_VERSION = 1;
// constructor
public AddressBookDatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// creates the contacts table when the database is created
@Override
public void onCreate(SQLiteDatabase db) {
// SQL for creating the contacts table
final String CREATE_CONTACTS_TABLE =
"CREATE TABLE " + Contact.TABLE_NAME + "(" +
Contact._ID + " integer primary key, " +
Contact.COLUMN_WORD + " TEXT, " +
Contact.COLUMN_TIP + " TEXT);";
db.execSQL(CREATE_CONTACTS_TABLE); // create the contacts table
}
// normally defines how to upgrade the database when the schema changes
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
/* SELECT RANDOM */
private void Exemplo(){
List<String> dados = new ArrayList();
SQLiteDatabase db = getReadableDatabase();
String selectQuery = "SELECT palavra FROM palavrasforca";
Cursor cursor = db.rawQuery(selectQuery, null);
if (cursor.moveToFirst()) {
do{
String palavra = cursor.getString(cursor.getColumnIndex("palavra"));
dados.add(palavra);
}while (cursor.moveToNext());
}
//aqui dados terá todos os valores do banco
}
}
And now the class I want to send:
public class Palavras {
private String[] palavras = new String[] {/* Gravar os valores da coluna aqui*/};
public Palavras() {
}
public String sorteio() {
String palavraSorteada = palavras[(int)(random()*palavras.length)];
return palavraSorteada;
}
public static double random() {
Random r = new Random();
return r.nextDouble();
}
}
I wonder how I could record the data from select in private String[] palavras = new String[] {};