enter code here
INFO_MAIN.xml设计视图
我正在为我的学校项目开发一个android
应用。 database
中已经创建了一个称为“原始物料主数据”的表,并且还插入了数据。
请参考上图,在RawName(Textview)的编辑文本前面输入原材料名称后,我希望在info1,info2,info3的编辑文本前面设置提示,其提示将从其值中获取。数据库表“原材料主数据”。我已经使用下面的代码来设置edittext值。
[IN INFO_MAIN.java]
public void rawmat() {
info1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rawMat = rm.getText().toString(); //fetching text from
//the edittext infront of raw material
Cursor res = dbb.getInfo("Info1",rawMat); //getinfo method is
//in the database helper class , it is pasted below
String info = res.getString(1);
info1.setText(info); // setting the edit text.
res = dbb.getInfo("Info2",rawMat); // repeating the same
//procedure for the edittext of info2.
info = res.getString(0);
dbb.SetEt(info, info2);
res = dbb.getInfo("Info3",rawMat);
info = res.getString(0);
dbb.SetEt(info, info3);
}
});
}
[`IN DATABASEHELPER.java]
public Cursor getInfo(String info,String rm)
{
SQLiteDatabase db=this.getReadableDatabase();
Cursor res=db.rawQuery("select "+info+"from "+table_name1 + "where RawName ="+rm,null);
res.moveToFirst();
return res;
}
public void SetEt(String x, EditText et)
{
et.setHint(x);
}`
此代码无效。您能帮我找到解决方法吗?
[在为原材料编辑文本添加文本观察器之后]
rm.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
String rawMat = rm.getText().toString();
Cursor res = dbb.getInfo("Info1", rawMat);
String info = res.getString(1);
info1.setText(info);
res = dbb.getInfo("Info2", rawMat);
info = res.getString(0);
dbb.SetEt(info, info2);
res = dbb.getInfo("Info3", rawMat);
info = res.getString(0);
dbb.SetEt(info, info3);
}
});