Пример #1
0
  private void setData(List<GiftHistoryItem> data) {
    this.data = data;
    containerView.removeAllViews();
    LayoutInflater inflater =
        (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (GiftHistoryItem giftHistoryItem : data) {
      View v = inflater.inflate(R.layout.gift_history_item, null);
      ((TextView) v.findViewById(R.id.name)).setText(giftHistoryItem.getGiftName());
      ((TextView) v.findViewById(R.id.pie)).setText(giftHistoryItem.getPieQty() + " pie");
      ((TextView) v.findViewById(R.id.time)).setText(giftHistoryItem.getTxnDate());
      ((TextView) v.findViewById(R.id.status))
          .setText(giftHistoryItem.getStatus().equals("N") ? "Đang chờ" : "Thành công");
      containerView.addView(v);
      v.setTag(giftHistoryItem);

      v.findViewById(R.id.btn_cancel).setTag(giftHistoryItem);
      v.findViewById(R.id.btn_cancel)
          .setOnClickListener(
              new OnClickListener() {

                @Override
                public void onClick(final View v) {
                  DialogUtility.showYesNoDialog(
                      getActivity(),
                      R.string.gift_cancel_message,
                      R.string.btn_ok,
                      R.string.btn_cancel,
                      new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                          requestCancelGift((GiftHistoryItem) v.getTag());
                        }
                      });
                }
              });

      v.setOnClickListener(
          new OnClickListener() {

            @Override
            public void onClick(View v) {
              if (v.findViewById(R.id.btn_cancel).getVisibility() == View.GONE) {
                v.findViewById(R.id.btn_cancel).setVisibility(View.VISIBLE);
              } else {
                v.findViewById(R.id.btn_cancel).setVisibility(View.GONE);
              }
            }
          });
    }
  }
Пример #2
0
  public void requestCancelGift(final GiftHistoryItem item) {
    List<NameValuePair> nameValuePairs = ParameterFactory.requestCancelGift(item.getTxnId());
    AsyncHttpPost postGetGiftList =
        new AsyncHttpPost(
            getActivity(),
            new AsyncHttpResponseProcess(getActivity()) {
              @Override
              public void processIfResponseSuccess(String response) {
                try {
                  JSONObject jsonObject = new JSONObject(response);
                  //							log.m(">>>>>>>>>>>>> " + response);
                  DialogUtility.alert(getActivity(), "Hủy quà thành công");
                  data.remove(item);
                  setData(data);
                } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
                  DialogUtility.alert(getActivity(), "Hủy quà thất bại");
                }
              }

              @Override
              public void processIfResponseFail() {
                log.e("failed ", "failed");
              }
            },
            nameValuePairs,
            true);
    postGetGiftList.execute(WebServiceConfig.URL_REQUEST_CANCEL_GIFT);
  }