Java 文本更改时从sqlite数据库获取特定行
我的sqlite数据库中有多条记录,当文本更改(“日期编辑文本”中的日期更改)时,我希望相应的行显示在表中。下面的代码适用于数据库中的最后一条记录,但我不知道如何显示与所选日期对应的行。请帮助我,因为我对安卓相当陌生。 这是我的代码:Java 文本更改时从sqlite数据库获取特定行,java,android,database,sqlite,android-studio,Java,Android,Database,Sqlite,Android Studio,我的sqlite数据库中有多条记录,当文本更改(“日期编辑文本”中的日期更改)时,我希望相应的行显示在表中。下面的代码适用于数据库中的最后一条记录,但我不知道如何显示与所选日期对应的行。请帮助我,因为我对安卓相当陌生。 这是我的代码: public class measurement extends AppCompatActivity{ Button button; EditText Date; int index=0; TextView HEIGHT,W
public class measurement extends AppCompatActivity{
Button button;
EditText Date;
int index=0;
TextView HEIGHT,WEIGHT,BMI,BLOODPRESSURE,PULSE,TEMPERATURE,GLUCOSELEVEL,OXYGENLEVEL;
DatabaseAdapterMeasurements MeasurementsDataBaseAdapter;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.measurement);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(measurement.this);
final DatePicker picker = new DatePicker(measurement.this);
picker.setCalendarViewShown(false);
builder.setTitle("Create Year");
builder.setView(picker);
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.setPositiveButton("Select", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int day = picker.getDayOfMonth();
int month = (picker.getMonth() + 1);
int year = picker.getYear();
Date.setText(day + "/" + month + "/" + year);
// Toast.makeText(measurement.this, picker.getDayOfMonth() + " / " + (picker.getMonth() + 1) + " / " + picker.getYear(), Toast.LENGTH_LONG).show();
}
});
builder.show();
}
});
MeasurementsDataBaseAdapter = new DatabaseAdapterMeasurements(this);
MeasurementsDataBaseAdapter = MeasurementsDataBaseAdapter.open();
Measurements studentCourse = new Measurements();
studentCourse.setDATE("ppp");
studentCourse.setEMAIL("hh@HOTMAIL.COM");
studentCourse.setREFERENCE("lkj");
studentCourse.setHEIGHT("1121");
studentCourse.setWEIGHT("CIS11");
studentCourse.setBMI("A-");
studentCourse.setBLOODPRESSURE("A-");
studentCourse.setPULSE("A-");
studentCourse.setTEMPERATURE("A-");
studentCourse.setGLUCOSELEVEL("A-");
studentCourse.setOXYGENLEVEL("A-");
MeasurementsDataBaseAdapter.insertEntry(studentCourse);
studentCourse.setDATE("lll");
studentCourse.setEMAIL("v=bb@HOTMAIL.COM");
studentCourse.setREFERENCE("uhu");
studentCourse.setHEIGHT("111");
studentCourse.setWEIGHT("CIS11");
studentCourse.setBMI("A-");
studentCourse.setBLOODPRESSURE("A-");
studentCourse.setPULSE("A-");
studentCourse.setTEMPERATURE("A-");
studentCourse.setGLUCOSELEVEL("A-");
studentCourse.setOXYGENLEVEL("A-");
MeasurementsDataBaseAdapter.insertEntry(studentCourse);
studentCourse.setDATE("jjj");
studentCourse.setEMAIL("cc@HOTMAIL.COM");
studentCourse.setREFERENCE("lol");
studentCourse.setHEIGHT("1671");
studentCourse.setWEIGHT("CIS11");
studentCourse.setBMI("A-");
studentCourse.setBLOODPRESSURE("A-");
studentCourse.setPULSE("A-");
studentCourse.setTEMPERATURE("A-");
studentCourse.setGLUCOSELEVEL("A-");
studentCourse.setOXYGENLEVEL("A-");
MeasurementsDataBaseAdapter.insertEntry(studentCourse);
studentCourse.setDATE("jjj");
studentCourse.setEMAIL("hhfg@HOTMAIL.COM");
studentCourse.setREFERENCE("plo");
studentCourse.setHEIGHT("1091");
studentCourse.setWEIGHT("CIS11");
studentCourse.setBMI("A-");
studentCourse.setBLOODPRESSURE("A-");
studentCourse.setPULSE("A-");
studentCourse.setTEMPERATURE("A-");
studentCourse.setGLUCOSELEVEL("A-");
studentCourse.setOXYGENLEVEL("A-");
MeasurementsDataBaseAdapter.insertEntry(studentCourse);
List<Measurements> measurements= MeasurementsDataBaseAdapter.getAllMeasurements();
HEIGHT = (TextView) findViewById(R.id.HEIGHT);
WEIGHT = (TextView) findViewById(R.id.WEIGHT);
BMI = (TextView) findViewById(R.id.BMI);
BLOODPRESSURE = (TextView) findViewById(R.id.BP);
PULSE = (TextView) findViewById(R.id.PULSE);
TEMPERATURE=(TextView) findViewById(R.id.TEMP );
GLUCOSELEVEL = (TextView) findViewById(R.id.GL);
OXYGENLEVEL = (TextView) findViewById(R.id.OL);
Date = (EditText) findViewById(R.id.Date);
for(Measurements mn: measurements)
{
String log="EMAIL"+mn.getEMAIL()+"REFERENCE"+mn.getREFERENCE()+"HEIGHT"+mn.getHEIGHT()+"WEIGHT"+mn.getWEIGHT()+"BMI"+mn.getBMI()+"BLOODPRESSURE"+mn.getBLOODPRESSURE()+"PULSE"+mn.getPULSE()+"TEMPERATURE"+mn.getTEMPERATURE()+"GLUCOSELEVEL"+mn.getGLUCOSELEVEL()+"OXYGENLEVEL"+mn.getOXYGENLEVEL();
HEIGHT.setText(mn.getHEIGHT());
WEIGHT.setText(mn.getWEIGHT());
BMI.setText(mn.getBMI());
BLOODPRESSURE.setText(mn.getBLOODPRESSURE());
PULSE.setText(mn.getPULSE());
TEMPERATURE.setText(mn.getTEMPERATURE());
GLUCOSELEVEL.setText(mn.getGLUCOSELEVEL());
OXYGENLEVEL.setText(mn.getOXYGENLEVEL());
}
}
}
公共类度量扩展了活动{
按钮;
编辑文本日期;
int指数=0;
text查看身高、体重、BMI、血压、脉搏、体温、血糖水平、氧水平;
数据库适配器测量测量数据库适配器;
创建时受保护的void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.measurement);
按钮=(按钮)findViewById(R.id.button);
setOnClickListener(新视图.OnClickListener(){
公共void onClick(视图v){
AlertDialog.Builder=新建AlertDialog.Builder(measurement.this);
最终日期选择器=新日期选择器(measurement.this);
picker.SetCalendarViewShowed(假);
建造商名称(“创建年份”);
builder.setView(选择器);
setNegativeButton(“取消”,新建DialogInterface.OnClickListener()){
@凌驾
public void onClick(DialogInterface dialog,int which){
dialog.dismise();
}
});
setPositiveButton(“选择”,新建DialogInterface.OnClickListener(){
@凌驾
public void onClick(DialogInterface dialog,int which){
int day=picker.getDayOfMonth();
int month=(picker.getMonth()+1);
int year=picker.getYear();
Date.setText(日+“/”+月+“/”+年);
//Toast.makeText(measurement.this,picker.getDayOfMonth()+“/”+(picker.getMonth()+1)+“/”+picker.getYear(),Toast.LENGTH_LONG).show();
}
});
builder.show();
}
});
MeasurementsDataBaseAdapter=新的DatabaseAdapter度量(此);
MeasurementsDataBaseAdapter=MeasurementsDataBaseAdapter.open();
测量学生课程=新测量();
学生课程设置日期(“ppp”);
studentCourse.setEMAIL(“hh@HOTMAIL.COM");
学生课程设置参考(“lkj”);
学生课程设置高度(“1121”);
学生课程设定体重(“CIS11”);
studentCourse.setBMI(“A-”);
学生课程。挫折压力(“A-”);
设置脉冲(“A-”);
学生课程。设定温度(“A-”);
studentCourse.setGLUCOSELEVEL(“A-”);
学生课程。setOXYGENLEVEL(“A-”);
MeasurementsDataBaseAdapter.insertEntry(学生课程);
学生课程设置日期(“lll”);
studentCourse.setEMAIL(“v=bb@HOTMAIL.COM");
学生课程设置参考(“uhu”);
学生课程设置高度(“111”);
学生课程设定体重(“CIS11”);
studentCourse.setBMI(“A-”);
学生课程。挫折压力(“A-”);
设置脉冲(“A-”);
学生课程。设定温度(“A-”);
studentCourse.setGLUCOSELEVEL(“A-”);
学生课程。setOXYGENLEVEL(“A-”);
MeasurementsDataBaseAdapter.insertEntry(学生课程);
学生课程设置日期(“jjj”);
studentCourse.setEMAIL(“cc@HOTMAIL.COM");
studentCourse.setREFERENCE(“lol”);
学生课程设置高度(“1671”);
学生课程设定体重(“CIS11”);
studentCourse.setBMI(“A-”);
学生课程。挫折压力(“A-”);
设置脉冲(“A-”);
学生课程。设定温度(“A-”);
studentCourse.setGLUCOSELEVEL(“A-”);
学生课程。setOXYGENLEVEL(“A-”);
MeasurementsDataBaseAdapter.insertEntry(学生课程);
学生课程设置日期(“jjj”);
studentCourse.setEMAIL(“hhfg@HOTMAIL.COM");
学生课程参考(“plo”);
学生课程。设置高度(“1091”);
学生课程设定体重(“CIS11”);
studentCourse.setBMI(“A-”);
学生课程。挫折压力(“A-”);
设置脉冲(“A-”);
学生课程。设定温度(“A-”);
studentCourse.setGLUCOSELEVEL(“A-”);
学生课程。setOXYGENLEVEL(“A-”);
MeasurementsDataBaseAdapter.insertEntry(学生课程);
List measurements=MeasurementsDataBaseAdapter.GetAllMeasures();
高度=(TextView)findViewById(R.id.HEIGHT);
权重=(TextView)findViewById(R.id.WEIGHT);
BMI=(TextView)findViewById(R.id.BMI);
血压=(TextView)findViewById(R.id.BP);
脉冲=(TextView)findViewById(R.id.PULSE);
温度=(TextView)findViewById(R.id.TEMP);
GLUCOSELEVEL=(TextView)findViewById(R.id.GL);
OXYGENLEVEL=(TextView)findViewById(R.id.OL);
日期=(EditText)findViewById(R.id.Date);
测量(mn:测量)
{
字符串log=“EMAIL”+mn.getEMAIL()+“REFERENCE”+mn.getREFERENCE()+“HEIGHT”+mn.getHEIGHT()+“WEIGHT”+mn.getWEIGHT()+“BMI”+mn.getBMI()+“BLOODPRESSURE”+mn.getBLOODPRESSURE()+“PULSE”+mn.getPULSE()+“TEMPERATURE”+mn.getTEMPERATURE()+“GLUCOSELEVEL”+mn.getGLUCOSELEVEL()+“OXYGENLEVEL”+mn.getOXYGENLEVEL();
HEIGHT.setText(mn.getHEIGHT());
WEIGHT.setText(mn.getWEIGHT());
BMI.setText(mn.getBMI());
BLOODPRESSURE.setText(mn.getBLOODPRESSURE());
PULSE.setText(mn.getPULSE());
TEMPERATURE.setText(mn.getTEMPERATURE());
GLUCOSELEVEL.setText(mn.getGLUCOSELEVEL());
setText(mn.getOXYGENLEVEL());
}
}
}
尝试这样做
public Cursor getData(String qno) {
Cursor cursor = null;
SQLiteDatabase db = this.getReadableDatabase();
cursor = db.rawQuery("SELECT * FROM QuizTable WHERE qno=?", new String[] { qno + ""});
if(cursor.getCount() > 0) {
cursor.moveToFirst();
}
return cursor;
}// method body finish