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); } } }); } }