我在SQLite数据库中创建了2个表,并且stoksales
at DatabaseHelper.java
创建表stok
String tbStok = "CREATE TABLE stok(id_stok INTEGER PRIMARY KEY AUTOINCREMENT, waktu_stok DATETIME, id_sales INTEGER, stok INTEGER, FOREIGN KEY id_sales REFERENCES sales(id_sales)";
创建表sales
String tbSales = "CREATE TABLE sales(id_sales INTEGER PRIMARY KEY AUTOINCREMENT, nama VARCHAR, kodesales VARCHAR, username VARCHAR, password VARCHAR, level INTEGER)";
从 SQLite 创建列表数据
public List<String> getSpinnerSales(){
List<String> labels = new ArrayList<String>();
// Select All Query
String selectQuery = "SELECT * FROM " + "sales";
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
labels.add(cursor.getString(0));
labels.add(cursor.getString(1));
} while (cursor.moveToNext());
}
// closing connection
cursor.close();
db.close();
// returning lables
return labels;
}
在微调器上显示
private void loadSpinnerSales() {
// database handler
DatabaseHelper db = new DatabaseHelper(getApplicationContext());
// Spinner Drop down elements
List<String> lables = db.getSpinnerSales();
// Creating adapter for spinner
ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_spinner_item, lables);
// Drop down layout style - list view with radio button
dataAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapter to spinner
spsales.setAdapter(dataAdapter);
}
我需要将值保存到其他表 SQLite,但微调器必须显示销售名称。id_sales
手掌心
明月笑刀无情
翻阅古今
相关分类