Ejemplo n.º 1
0
 @Override
 public boolean onContextItemSelected(MenuItem item) {
   if (getUserVisibleHint()) {
     AdapterView.AdapterContextMenuInfo info =
         (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
     ShekelReceipt receipt = (ShekelReceipt) getListAdapter().getItem((int) info.id);
     switch (item.getItemId()) {
       case R.id.action_add:
         mainActivity.addNewReceipt(event);
         return true;
       case R.id.action_delete:
         JsonObjectRequest request =
             new JsonObjectRequest(
                 Request.Method.GET,
                 ShekelNetwork.getInstance(getContext()).getUrlForDeleteReceipt(event, receipt),
                 null, // no parameters post
                 new Response.Listener<JSONObject>() {
                   @Override
                   public void onResponse(JSONObject response) {
                     mainActivity.showReceiptList(event);
                     Log.d(
                         "Receipt Fragment",
                         "onErrorResponse() called with: " + "error = [" + response + "]");
                   }
                 },
                 new Response.ErrorListener() {
                   @Override
                   public void onErrorResponse(VolleyError error) {
                     mainActivity.showReceiptList(event);
                     Log.d(
                         "Receipt Fragment",
                         "onErrorResponse() called with: " + "error = [" + error + "]");
                   }
                 });
         ShekelNetwork.getInstance(getContext()).addToRequestQueue(request);
         return true;
       case R.id.action_edit:
         mainActivity.changeReceipt(event, receipt);
         return true;
       default:
         return super.onContextItemSelected(item);
     }
   }
   return super.onContextItemSelected(item);
 }
Ejemplo n.º 2
0
 @Override
 public void onListItemClick(ListView l, View v, int position, long id) {
   super.onListItemClick(l, v, position, id);
   mainActivity.showItemList(event, (ShekelReceipt) l.getAdapter().getItem(position));
 }