1

如何将值从OnItemSelectedListener类(附加到微调器)传递到DatabaseHelper( SQLiteOpenHelper) 类?

我正在尝试使用设置器,DatabaseHelper但由于某种原因它不起作用。:|

MyOnItemSelectedListener:

public void onItemSelected(AdapterView<?> parent, View view, int pos,
        long id) {

    switch (parent.getId()) {
    case R.id.spinner1:
        DatabaseHelper myDbHelper = new DatabaseHelper(getBaseContext());
        myDbHelper = new DatabaseHelper(this);
        stringc = String.valueOf(parent.getSelectedItemId());
        Toast.makeText(parent.getContext(), "Carreira: " + stringc,
                Toast.LENGTH_LONG).show();
        myDbHelper.setC(stringc);
        break;
    case R.id.spinner2:
        stringpf = String.valueOf(parent.getSelectedItemId());
        Toast.makeText(parent.getContext(), "PFuncionamento: " + stringpf,
                Toast.LENGTH_LONG).show();
        DatabaseHelper.setPF(stringpf);
        break;
    }

数据库助手:

public void setC(String stringC) {
c = stringC;
}

...

public static Cursor getPFunc() {
    return bd
            .rawQuery(
                    "SELECT * FROM PeriodoFuncionamento a INNER JOIN Horario b ON a._id=b.PeriodoFuncionamentoID WHERE b._id = ? GROUP BY a._id",
                    new String[] { c });

提前致谢。:)

4

0 回答 0