php - In Android How to show message when data is Changed into Database? -
i need show message in android java class when data changed database. method has used this??
please me , dont have idea this.
this php code:
<?php $tableid=$_post['tableid']; $status=$_post['status']; include '../../dbconnect.php'; if($status=='all') { $oidquery="select orderid, orderstatus din_orders tableid=$tableid && orderstatus!='pending'"; } else { $oidquery="select orderid,orderstatus din_orders tableid=$tableid && orderstatus='$status'"; } $result=mysql_query($oidquery); while($ordersrow=mysql_fetch_object($result)) { $ordersarray[]=$ordersrow; } echo json_encode(array('orders'=>$ordersarray)); ?>
for example: in table "orderstatus" shows "pending" later manually change "pending" "delivered". when change takes place in database should message in android java class "items delivered".
here android java code:
public void ordersdisplay() { string selectedstatus1 = (string) status.getselecteditem(); arraylist<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(); arraylist<hashmap<string, string>> mylist = new arraylist<hashmap<string, string>>(); namevaluepairs.add(new basicnamevaluepair("tableid", tableid1)); namevaluepairs.add(new basicnamevaluepair("status", selectedstatus1)); inputstream = null; string result = ""; jsonobject jarray = null; try { httpclient httpclient = new defaulthttpclient(); httppost httppost = new httppost(url + "order_status.php"); httppost.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = httpclient.execute(httppost); httpentity entity = response.getentity(); = entity.getcontent(); } catch (exception e) { log.e("log", "error in connection" + e.tostring()); toast.maketext(getapplicationcontext(), "error in connection", toast.length_short).show(); } try { bufferedreader reader = new bufferedreader(new inputstreamreader( is, "iso-8859-1"), 8); stringbuilder sb = new stringbuilder(); string line = ""; while ((line = reader.readline()) != null) { sb.append(line + "\n"); } is.close(); result = sb.tostring(); } catch (exception e) { // todo: handle exception } try { jarray = new jsonobject(result); jsonarray jsonarray = jarray.getjsonarray("orders"); (int = 0; < jsonarray.length(); i++) { hashmap<string, string> map = new hashmap<string, string>(); jsonobject jsonobject = jsonarray.getjsonobject(i); map.put("orders", string.valueof(i)); map.put("orderid", jsonobject.getstring("orderid")); map.put("status", jsonobject.getstring("orderstatus")); mylist.add(map); } } catch (jsonexception e) { toast.maketext(getapplicationcontext(), "no order display", toast.length_long).show(); log.e("log_tag", "error parsing data " + e.tostring()); } listadapter adapter = new simpleadapter(this, mylist, r.layout.vieworder, new string[] { "orderid", "status" }, new int[] { r.id.item_title, r.id.item_subtitle }); setlistadapter(adapter); final listview lv = getlistview(); lv.settextfilterenabled(true); lv.setonitemclicklistener(new onitemclicklistener() { public final void onitemclick(adapterview<?> parent, view view, int position, long id) { @suppresswarnings("unchecked") hashmap<string, string> o = (hashmap<string, string>) lv .getitematposition(position); string orderid = o.get("orderid"); string orderstatus = o.get("status"); intent intent = new intent(getapplicationcontext(), din_ord_itemdisplay.class); intent.putextra("orderid", orderid); intent.putextra("waitername", waitername); intent.putextra("orderstatus", orderstatus); intent.putextra("tableid", tableid1); intent.putextra("url", url); startactivity(intent); } }); }
if inserting values in sqlite database following
contentvalues values = new contentvalues(); values.put(dbhelper.book_title,"android"); values.put(dbhelper.book_author,"abc"); database = dbhelper.getwritabledatabase(); database.insert(dbhelper.table_name, null, values);
here database.insert returns row id of newly inserted row, or -1 if error occurred.
so can have following validation.
if (database.insert(dbhelper.table_name, null, values) != -1) { toast.maketext(this, "write success", toast.length_short).show(); } else { toast.maketext(this, "write failure", toast.length_short).show(); }
Comments
Post a Comment