Android 如何比较数据库数据?
如何编写代码来比较Firebase中的数据?在我的Firebase下的医学是“糖尿病”,当用户想要购买药物时,如何使数据库自动比较用户信息,如果用户患有糖尿病,它将不允许用户购买药物 用户信息Android 如何比较数据库数据?,android,firebase,Android,Firebase,如何编写代码来比较Firebase中的数据?在我的Firebase下的医学是“糖尿病”,当用户想要购买药物时,如何使数据库自动比较用户信息,如果用户患有糖尿病,它将不允许用户购买药物 用户信息 public UserInformation(String name, String address, String phone_num,String gender,String country,String medicine,String medical) { this.address
public UserInformation(String name, String address, String phone_num,String gender,String country,String medicine,String medical) {
this.address = address;
this.name = name;
this.phone_num = phone_num;
this.gender = gender;
this.country = country;
this.medicine = medicine;
this.medical = medical;
}
public String getMedical(){return medical;}
public void setMedical(String medical){this.medical = medical;}
在Databasehalper类中 String sql=“SELECT*FROM TABLENAME WHERE Name=”+datamodel_app.getFood_Name()+“”; cursor=mDatabase.rawQuery(sql,null); if(cursor.getCount()>0) { //在这里执行您的代码 } 否则{ }
})) 伙计,他用的是firebase而不是Sqlite如何使用Snackbar?我无法使用Snackbar我已经编辑了我的代码可以帮我检查吗?将google设计库添加到你的gradle文件添加这个,实现'com.android.support:design:26.1.0'或转到文件->项目结构->依赖项->单击绿色添加按钮->库依赖项->查找设计库我无法将其添加到我的库中可能我没有更新我的android studio,因为我担心以后更新时会出现一些错误。那么,没有Snackbar还有其他方法可以使用吗?你能告诉我你的UserInformation类吗?告诉我第56行和第87行你需要确保firebase数据结构中的每个用户在UserInformation类中都有相同的值例如,您的一些用户没有医疗节点,然后它将返回null,但我在患有糖尿病的用户身上尝试,它会显示错误
public UserInformation(String name, String address, String phone_num,String gender,String country,String medicine,String medical) {
this.address = address;
this.name = name;
this.phone_num = phone_num;
this.gender = gender;
this.country = country;
this.medicine = medicine;
this.medical = medical;
}
public String getMedical(){return medical;}
public void setMedical(String medical){this.medical = medical;}
DatabaseReference mReference = FirebaseDatabase.getInstance().getReference();
FirebaseAuth auth = FirebaseAuth.getInstance();
FirebaseUser mUser = auth.getCurrentUser();
// this code will check if user has Diabetes or not
mReference.child("Users").child(user.getUid()).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
UserClass user = dataSnapshot.getValue(UserClass.class);
if(user!=null)
{
if(user.medical.equals("Diabetes"))
Snackbar.make(findViewById(android.R.id.content),"Diabetes",Snackbar.LENGTH_LONG).show();
else
Snackbar.make(findViewById(android.R.id.content),"Not Not Diabetes",Snackbar.LENGTH_LONG).show();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}