Add to
Final person p2 = new person ();
Button Bt=findviewbyid (R.ID.BT);
Bt.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string= ((EditText) Findviewbyid (R.id.et1)). GetText (). toString ();
P2.setname (string);
P2.save (New savelistener<string> () {
@Override
public void-Done (String objectId, bmobexception e) {
if (e==null) {
Toast.maketext (Getapplicationcontext (), "Add data successfully, return ObjectId as:" +objectid,toast.length_short). Show ();
}else{
Toast.maketext (Getapplicationcontext (), "Failed to create data:" + e.getmessage (), Toast.length_short). Show ();
}
}
});
}
});
Inquire
Button Bt2=findviewbyid (R.ID.BT2);
Bt2.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string1= ((EditText) Findviewbyid (R.id.et2)). GetText (). toString ();
bmobquery<person> bmobquery = new bmobquery<person> ();
Bmobquery.getobject (string1, new querylistener<person> () {
@Override
public void do (Person object, bmobexception e) {
if (e==null) {
Toast.maketext (Getapplicationcontext (), "Query succeeded", Toast.length_short). Show ();
String St=object.getname ();
TextView Tv=findviewbyid (r.id.tv);
Tv.settext (ST);
}else{
Toast.maketext (Getapplicationcontext (), "Query failed:" + e.getmessage (), Toast.length_short). Show ();
}
}
});
}
});
Search in turn
String sql = "Select *from myaddbook";
New Bmobquery<person> (). Dosqlquery (SQL, new sqlquerylistener<person> () {
@Override
public void-Done (bmobqueryresult<person> Bmobqueryresult, bmobexception e) {
if (E = = null) {
list<person> list = (list<person>) bmobqueryresult.getresults ();
if (list = null && list.size () > 0) {
for (int i = 0; i < list.size (); i++) {
Person book = List.get (i);
}
} else {
}
}
}
});
Determine if the user name password is correct
Final String username= "";
Final String password= "";
String sql = "Select *from person";
New Bmobquery<person> (). Dosqlquery (SQL, new sqlquerylistener<person> () {
@Override
public void-Done (bmobqueryresult<person> Bmobqueryresult, bmobexception e) {
if (E = = null) {
list<person> list = (list<person>) bmobqueryresult.getresults ();
if (list = null && list.size () > 0) {
for (int i = 0; i < list.size (); i++) {
Person person = list.get (i);
if (Person.getusername () ==username&&person.getpassword () ==password) {//You can compare the user name first, find and then then compare the password
Successful login, for the person class, jump.
}
}
The user name or password error is displayed.
}
}
}
});
Delete
Button Bt3=findviewbyid (R.ID.BT3);
Bt3.setonclicklistener (New View.onclicklistener () {
@Override
public void OnClick (View v) {
String string2= ((EditText) Findviewbyid (R.id.et3)). GetText (). toString ();
P2.setobjectid (string2);
P2.delete (New Updatelistener () {
@Override
public void-Done (bmobexception e) {
if (e==null) {
Toast.maketext (Getapplicationcontext (), "Delete succeeded:" +p2.getupdatedat (), Toast.length_short). Show ();
}else{
Toast.maketext (Getapplicationcontext (), "Delete failed:" + e.getmessage (), Toast.length_short). Show ();
}
}
});
}
});
}
Modify
person P2 = new person ();
P2.setaddress ("Chaoyang, Beijing");
P2.update ("6b6c11c537", new Updatelistener () {
@Override
public void-Done (bmobexception e) {
if (e==null) {
Toast ("Update succeeded:" +p2.getupdatedat ());
}else{
Toast ("Update failed:" + e.getmessage ());
}
}
});
2018 Summer training functions for basic database operations