【发布时间】:2018-11-28 11:17:57
【问题描述】:
游标携带数据有问题,调试,我知道了"java.lang.IllegalStateException: Cannot perform this operation because the connection pool has been closed."。
但是我仍然无法调整光标问题,我知道在光标返回数据之前不应该关闭连接,但我不知道如何调整它。
我想从 getEmpData 方法中获取一些信息,然后传递它。
我的方法:
public Cursor getEmpData(Integer employeeID)
{
EmpDept = getReadableDatabase();
Integer[] empRow = {employeeID};
Cursor c = EmpDept.rawQuery("Select name, Title, phone, email from Employee where EmpID like ?", new String[]{employeeID.toString()});
if (c != null)
{
c.moveToFirst();
}
EmpDept.close();
return c;
}
列表视图部分:
单击名称时,它应该将数据移动到新活动。
namelist.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
{
String name = namelist.getItemAtPosition(position).toString();
//Getting ID of emp,dept
Cursor empID = Emp.getEmpID(name);
Cursor DepID = Emp.getDeptID(name);
int eID = empID.getInt(0);
int dID = DepID.getInt(0);
Intent intent = new Intent(MainActivity.this, empDetails.class);
intent.putExtra("empName", Emp.getEmpData(eID).toString());
intent.putExtra("empTitle",Emp.getEmpData(eID).toString());
intent.putExtra("empPhone",Emp.getEmpData(eID).toString());
intent.putExtra("empEmail",Emp.getEmpData(eID).toString());
intent.putExtra("empDept",Emp.getDeptName(dID).toString());
startActivity(intent);
}
});
【问题讨论】:
-
请停止转发此问题。正如我上次提到的,只需使用您拥有的任何新信息、您尝试过的任何新代码或任何已发布答案不起作用的解释来编辑您的原始帖子,就会将它推到活动队列的顶部。
标签: java android sqlite cursor