如何从ANdroid中选定的微调项目中检索sqlite数据库中的id?

时间:2014-06-19 09:45:25

标签: java android sqlite

我想从Android中的Sqlite数据库中检索选定的微调器项目ID。当我想要选择任何微调器项目时,我想得到那个我必须选择的微调项目的ID。谢谢高级。 这是我的代码

spinnerProjectNames = (Spinner)findViewById(R.id.spinnerSelectProject);
        loadProjectsNameSpinnerData();
        spinnerProjectNames.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1,
                    int arg2, long arg3) {
                // TODO Auto-generated method stub
                selectedProjectName = spinnerProjectNames.getSelectedItem().toString().trim();
                System.out.println("selectedProjectName " + selectedProjectName);

                Cursor mCursor = db.rawQuery("SELECT project_id  FROM  project WHERE project_name= '"+selectedProjectName+"'" , null);
                        if (mCursor != null ) {

                            {
                                mCursor.moveToFirst();
                                int projectId=mCursor.getInt(0);
                                String strProjectId = String.valueOf(projectId);



                             System.out.println("strProjectId = " + strProjectId);

                            }

                          }

            }

            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub

            }
        });

0 个答案:

没有答案