jeudi 8 octobre 2015

Error Spinner SQLite

I have implemented a spinner from SQLite and and when I select the content the following message appears: "android.database.sqlite.SQLiteCursor@..." Any suggestions on how to solve it?

spAlimento = (Spinner) findViewById(R.id.sp_alimento)

        DatabaseHelper admin_SpAlimentos = new DatabaseHelper(this);
        SQLiteDatabase bd_SpAlimentos = admin_SpAlimentos.getWritableDatabase();

    Cursor curAlimentos= bd_SpAlimentos.rawQuery("select _id as _id, ALIMENTOS from DataBase where CLASIFICACION= "+'"'+"Cereales"+'"',null);
    if (curAlimentos.moveToFirst()){
        startManagingCursor(curAlimentos);
        String[] fromAlimentos= new String[]{"ALIMENTOS"};
        int[]toAlimentos=new int[]{android.R.id.text1};

        SimpleCursorAdapter adapterAlimentos=new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, curAlimentos, fromAlimentos, toAlimentos);

        adapterAlimentos.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spAlimento.setAdapter(adapterAlimentos);
    }
    else{
        Toast.makeText(this, "No exist",Toast.LENGTH_SHORT).show();}
    spAlimento.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View selectedItemView, int position, long id) {

            Toast.makeText(parent.getContext(), parent.getItemAtPosition(position).toString(),Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

Aucun commentaire:

Enregistrer un commentaire