Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/192.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用android中数据库的数据填充组合框_Android_Database_Combobox - Fatal编程技术网

用android中数据库的数据填充组合框

用android中数据库的数据填充组合框,android,database,combobox,Android,Database,Combobox,嗨,我所有的数据库都是这样的 public class Dbhelper extends SQLiteOpenHelper{ private static final String DATABASE_NAME="ComboBox.db"; private static final int SCHEMA_VERSION=1; public SQLiteDatabase db; public String [][] isiDb={ {"MI","Minimarket"},{"IDM

嗨,我所有的数据库都是这样的

public class Dbhelper extends SQLiteOpenHelper{

private static final String DATABASE_NAME="ComboBox.db";
private static final int SCHEMA_VERSION=1;
public SQLiteDatabase db;
public String [][] isiDb={
        {"MI","Minimarket"},{"IDM","Indomaret"},{"CRM","Ceriamart"},{"OMI","OMI"},{"CK","Circle K"},
        {"7EL","7 Eleven"},{"STM","Starmart"},{"AX","Alfa Express"},{"MID","Alfa Midi"},{"LWN","Lawson"},
        {"YMT","Yomart"},{"HRO","Hero"},{"SDO","Superindo"},{"HPM","Hypermart"},{"SWN","Swalayan"}

};

public Dbhelper(Context context) {
    super(context, DATABASE_NAME, null, SCHEMA_VERSION);
}

@Override
public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE isicombo (kdcombo text PRIMARY KEY,descp text)");
    for(int i=0; i<=1;i++)
     {
         db.execSQL("INSERT INTO isicombo(kdcombo,descp) VALUES ('"+isiDb[i][0]+"','"+isiDb[i][1]+"')");
     }
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // no-op, since will not be called until 2nd schema
    // version exists
    db.execSQL("DROP TABLE IF EXIST ComboBox.db");
    onCreate(db);

}

public Cursor getAllProjectss() {
    // TODO Auto-generated method stub
    return(getReadableDatabase()
            .rawQuery("SELECT * from isicombo",null));
}
public class CobaCombo extends Activity implements AdapterView.OnItemSelectedListener {

TextView selection;
Dbhelper helper = new Dbhelper(this);
String temp;


@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);
    selection = (TextView) findViewById(R.id.selection);
    Spinner spin = (Spinner) findViewById(R.id.spinner);
    Cursor anu = helper.getAllProjectss();
    if(anu.moveToFirst()){
        do{
            temp += anu.getString(1);

        }while(anu.moveToNext());
    }

    String[] isi = { ""+temp+"" };
    System.out.println(isi);    
    spin.setOnItemSelectedListener(this);
    ArrayAdapter<String> aa = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, isi);
    aa.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spin.setAdapter(aa);

}
public类Dbhelper扩展了SQLiteOpenHelper{
私有静态最终字符串数据库\u NAME=“ComboBox.db”;
私有静态最终int模式_版本=1;
公共数据库数据库;
公共字符串[][]isiDb={
{“MI”,“Minimarket”},{“IDM”,“Indomaret”},{“CRM”,“Ceriamart”},{“OMI”,“OMI”},{“CK”,“Circle K”},
"7EL","7 11","STM","Starmart","AX","Alfa Express","MID","Alfa Midi,
{“YMT”、“Yomart”}、{“HRO”、“Hero”}、{“SDO”、“Superndo”}、{“HPM”、“Hypermart”}、{“SWN”、“Swalayan”}
};
公共Dbhelper(上下文){
super(上下文、数据库名称、null、模式版本);
}
@凌驾
public void onCreate(SQLiteDatabase db){
execSQL(“创建表isicombo(kdcombo文本主键,descp文本)”;

对于(inti=0;i您现在可以进行查询,使用该查询返回一个值

现在,您必须遍历游标并获取所需的数据

db.execSQL(“创建表isicombo(kdcombo文本主键,descp文本)”;

最后添加

db.execSQL(“创建表isicombo(kdcombo文本主键,descp文本);”;


与您对Insert语句所犯的错误相同。

是的,是的。。但如何用数据库填充组合框?然后将其检索到组合框中
Cursor mCursor = mSQLiteDatabase.rawQuery("Select * from myTable", null);