I want to make a query and use the value entered by the user in the edittext as condition is the where clause. In database helper.java class: The query is the following:
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;
}
In 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();
}
When running the application, selecting in the editext patientid and clicking on the button it gives me always: No patient history found , even if the patient has examination history. Please help.. thank you in advance
Aucun commentaire:
Enregistrer un commentaire