查询无法正常查询

时间:2016-01-06 11:48:10

标签: java sqlite jquery-mobile

我想进行查询并使用用户在edittext中输入的值,因为condition是where子句。 在数据库helper.java类中: 查询如下:

public Cursor patientHisto ( String value ) {
    SQLiteDatabase db = this.getWritableDatabase();
 Cursor res = db.rawQuery (" select dateap,diagnostic,prestreatment from patients_table, appointments_table, examinations_table where patients_table.id = appointments_table.idp and appointments_table.idap = examinations_table.id_ap and ID = ?  order by name, familyname asc"  , new String[] {value} );
        return res;
    }

在ExaminatFragment.java中:

public class ExaminatFragment extends Fragment {
    DatabaseHelper myDB;
    EditText id_p;
    Button showhp;
     String value;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState){
    View v = inflater.inflate(R.layout.fragment_examinat, parent, false);
    myDB = new DatabaseHelper(getActivity());

    id_p = (EditText)v.findViewById(R.id.id_p_text);


    getPatHisto( );
    return v;
    }   

public void getPatHisto( ) {

     value = id_p.getText().toString();

    showhp.setOnClickListener(

                new View.OnClickListener() {

        @Override
        public void onClick(View v) {
        Cursor res = myDB.patientHisto(value);
        if (res.getCount() == 0){

    showMessage("Patient history", "No patient history found");
        return;

                    }


        StringBuffer buffer = new StringBuffer();
        while (res.moveToNext()){
                            buffer.append("Dateap:"+res.getString(0)+"\n");
                            buffer.append("Diagnostic:"+res.getString(1)+"\n");
                            buffer.append("Prestreatment:"+res.getString(2)+"\n\n");




                        }
                showMessage("Patient's history", buffer.toString());
                    }


                }
                );
                }






public void showMessage(String title, String Message){

        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        builder.setCancelable(true);
        builder.setTitle(title);
        builder.setMessage(Message);
        builder.show();

    }

在运行应用程序时,选择editext patientid并单击按钮,它始终给我:即使患者有检查历史记录,也没有找到患者病史。 请帮助..提前谢谢

1 个答案:

答案 0 :(得分:1)

在设置活动时,您只能抓取EditText的内容。

每次按下按钮时,将value = id_p.getText().toString();移动到点击侦听器内以捕获当前内容。