0

hi all i have database like this

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));
}

i want to create a combobox and i want fill this combobox with data from my database..i confused how fill the data into combobox..can you give me a simple code??thank you

i try with my code like this

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);

}

but combo box fill data from database in long string..not dropdown item..please help me

akubabas
  • 473
  • 5
  • 13
  • 28

2 Answers2

0

You can now make a Query using rawQuery which returns you a Cursor.

Cursor mCursor = mSQLiteDatabase.rawQuery("Select * from myTable", null);

Now, you have to iterate through cursor and fetch the required data. Here is the example code.

Community
  • 1
  • 1
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
0

In your Statement

db.execSQL("CREATE TABLE isicombo (kdcombo text PRIMARY KEY,descp text)");

Add ; at last.

db.execSQL("CREATE TABLE isicombo (kdcombo text PRIMARY KEY,descp text);");

The same mistake you have done with Insert Statement.

Bhavin
  • 6,020
  • 4
  • 24
  • 26