データがデータベースに変更されたときに、Android Java クラスでメッセージを表示する必要があります。これを行うにはどのような方法を使用する必要がありますか??
私を助けてください、私はこれについて何の考えも持っていません。
これは私のPHPコードです:
<?php
$tableid=$_POST['Tableid'];
$status=$_POST['Status'];
include '../../dbconnect.php';
if($status=='All')
{
$oidquery="select orderid, orderstatus from din_orders where tableid=$tableid && orderstatus!='Pending'";
}
else
{
$oidquery="select orderid,orderstatus from din_orders where tableid=$tableid && orderstatus='$status'";
}
$result=mysql_query($oidquery);
while($ordersrow=mysql_fetch_object($result))
{
$ordersarray[]=$ordersrow;
}
echo json_encode(array('orders'=>$ordersarray));
?>
例: テーブル「OrderStatus」では、最初は「保留中」と表示され、後で手動で「保留中」を「配達済み」に変更します。この変更がデータベースで行われると、Android Java クラスで「Items Delivered」というメッセージが表示されます。
ここに私のAndroid Javaコードがあります:
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 is = 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();
is = 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");
for (int i = 0; i < 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 to 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);
}
});
}