0
我在android studio中有一个数据库,其表名EMP_TABLE与列E_NAME,E_AGE和E_DEPT。 我的片段布局有两个editText字段,一个按钮和一个TextView字段。我想对该数据库执行查询,以便在第一个edittext字段中输入E_NAME属性时,在第二个edittext字段中输入E_AGE属性,然后在textView字段中按下E_AGE字段的相应属性按钮。 查询看起来像SELECT E_AGE FROM EMP_TABLE WHERE E_NAME = a1 AND E_DEPT = a2。我对游标和查询不太熟悉,请帮助我。 这就是我在OnClick方法中迄今为止所做的。任何帮助将不胜感激。在android SQLite数据库中运行查询
actTextView1 = (AutoCompleteTextView) view.findViewById(R.id.acTextView1);
actTextView2 = (AutoCompleteTextView) view.findViewById(R.id.acTextView2);
result = (TextView) view.findViewById(R.id.resultField);
calculateButton = (Button) view.findViewById(R.id.calBtn);
calculateButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
DatabaseHelper myDBhelper = new DatabaseHelper(getActivity());
String a1 = actTextView1.getText().toString();
String a2 = actTextView2.getText().toString();
c = myDBhelper.query("EMP_TABLE", null, null, null, null, null, null);
if (c.moveToFirst()) {
do {
Toast.makeText(getActivity(), "Age is: " + c.getString(0), Toast.LENGTH_LONG).show();
} while (c.moveToNext());
}
@DineshNeupane同一帐户:
从数据库中获取存储的值 –