我已經檢索到Spinner
中的所有第一列數據。我想在選擇微調項目時檢索SQLite數據。數據將顯示在EditText
s。但是當我運行應用程序時,數據無法顯示在EditText
中。有人可以給我一個建議嗎?提前致謝。如何從Android中選定的Spinner項目獲取SQLite數據
這裏是我的代碼
spinner_searchByEmpName = (Spinner)findViewById(R.id.searchByEmpName);
loadSerachBYProject() ;
spinner_searchByEmpName = (Spinner)findViewById(R.id.searchByEmpName);
loadSerachBYProject() ;
spinner_searchByEmpName.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
selectedEmployeeName = spinner_searchByEmpName.getSelectedItem().toString().trim();
System.out.println("selectedProjectName " + selectedEmployeeName);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
etEmpName=(EditText)findViewById(R.id.Delete_editText_StaffEmployee_Name);
etDepartment=(EditText)findViewById(R.id.Delete_editText_Department);
etDesignation=(EditText)findViewById(R.id.Delete_editText_Designation);
try {
databaseHelper = new DatabaseHelper(this);
db=databaseHelper.getReadableDatabase();
Cursor cursor = db.rawQuery("SELECT staff_emp_name, department, designation FROM employee_details WHERE staff_emp_name = ?",
new String[] { "" + selectedEmployeeName });
if(cursor!=null && cursor.moveToFirst())
{
etEmpName.setText(cursor.getString(cursor
.getColumnIndex("staff_emp_name")));
etDepartment.setText(cursor.getString(cursor
.getColumnIndex("department")));
etDesignation.setText(cursor.getString(cursor
.getColumnIndex("designation")));
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
同時運行該代碼會發生什麼我給你的鏈接看看? – Gunaseelan
@Gunaseelan:當我運行它不顯示任何錯誤,並沒有顯示edit_text的任何行數據。 – Robotics
好吧,現在打印'cursor.getCount()'並告訴我答案。 – Gunaseelan