List of usage examples for android.app AlertDialog cancel
@Override public void cancel()
From source file:com.example.de.taomi2.mediachooser.activity.HomeFragmentActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show();// w ww . j a va 2 s. c o m handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); VideoFragment videoFragment = (VideoFragment) fragmentManager.findFragmentByTag("tab2"); // if (videoFragment == null) { VideoFragment newVideoFragment = new VideoFragment(); newVideoFragment.addItem(fileUriString); } else { videoFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } else if (resultCode == RESULT_CANCELED) { // User cancelled the video capture } else { // Video capture failed, advise user } } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show(); handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); ImageFragment imageFragment = (ImageFragment) fragmentManager.findFragmentByTag("tab1"); if (imageFragment == null) { ImageFragment newImageFragment = new ImageFragment(); newImageFragment.addItem(fileUriString); } else { imageFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } } }
From source file:vn.tungdx.mediapicker.activities.HomeFragmentActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show();/* ww w . j a v a 2s. c o m*/ handler.postDelayed(new Runnable() { @Override public void run() { // Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); VideoFragment videoFragment = (VideoFragment) fragmentManager.findFragmentByTag("tab2"); // if (videoFragment == null) { VideoFragment newVideoFragment = new VideoFragment(); newVideoFragment.addItem(fileUriString); } else { videoFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } else if (resultCode == RESULT_CANCELED) { // User cancelled the video capture } else { // Video capture failed, advise user } } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show(); handler.postDelayed(new Runnable() { @Override public void run() { // Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); ImageFragment imageFragment = (ImageFragment) fragmentManager.findFragmentByTag("tab1"); if (imageFragment == null) { ImageFragment newImageFragment = new ImageFragment(); newImageFragment.addItem(fileUriString); } else { imageFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } } }
From source file:com.dycode.jepretstory.mediachooser.activity.HomeFragmentActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show();//from w ww . j a v a 2 s.c om handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); //android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); if (mVideoFragment == null) { VideoFragment newVideoFragment = new VideoFragment(); newVideoFragment.addItem(fileUriString); } else { mVideoFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } else if (resultCode == RESULT_CANCELED) { // User cancelled the video capture } else { // Video capture failed, advise user } } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show(); handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); if (mImageFragment == null) { ImageFragment newImageFragment = new ImageFragment(); newImageFragment.addItem(fileUriString); } else { mImageFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } } }
From source file:cl.smartcities.isci.transportinspector.dialogs.BusSelectionDialog.java
@NonNull @Override/*from www. ja va 2s. com*/ public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); LayoutInflater inflater = this.getActivity().getLayoutInflater(); final View dialog_view = inflater.inflate(R.layout.bus_selection_dialog, null); final Typeface iconTypeface = Typeface.createFromAsset(this.getContext().getAssets(), getActivity().getString(R.string.icon_font)); ((TextView) dialog_view.findViewById(R.id.suggestion_icon)).setTypeface(iconTypeface); builder.setView(dialog_view); builder.setCancelable(false); dialog = builder.create(); final Bundle bundle = getArguments(); ArrayList<Bus> buses = null; if (bundle != null) { buses = bundle.getParcelableArrayList(NotificationState.BUSES); } if (buses != null && !buses.isEmpty()) { dialog_view.findViewById(R.id.list_view).setVisibility(View.VISIBLE); setBusMap(buses); ArrayList<String> serviceList = new ArrayList<>(); serviceList.addAll(this.busMap.keySet()); BusSelectionAdapter adapter = new BusSelectionAdapter(this.getContext(), serviceList, busMap, new BusSelectionAdapter.ListViewAdapterListener() { @Override public void onPositiveClick(Bus bus) { dialog.cancel(); listener.onPositiveClick(bus); } @Override public void onNegativeClick() { dialog.cancel(); listener.onNegativeClick(); } }); ListView listView = (ListView) dialog_view.findViewById(R.id.list_view); listView.setAdapter(adapter); if (adapter.getCount() > VISIBLE_BUSES) { View item = adapter.getView(0, null, listView); item.measure(0, 0); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.MATCH_PARENT, (int) ((VISIBLE_BUSES + 0.5) * item.getMeasuredHeight())); listView.setLayoutParams(params); } } Button otherAcceptButton = (Button) dialog_view.findViewById(R.id.accept); otherAcceptButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { EditText serviceEditText = (EditText) dialog_view.findViewById(R.id.service_edit_text); EditText licensePlateEditText = (EditText) dialog_view.findViewById(R.id.license_plate_edit_text); String service = serviceEditText.getText().toString(); String licensePlate = licensePlateEditText.getText().toString(); ServiceHelper helper = new ServiceHelper(getContext()); if (ServiceValidator.validate(service) && helper.getColorId(Util.formatServiceName(service)) != 0) { service = Util.formatServiceName(service); if (licensePlate.equals("")) { licensePlate = Constants.DUMMY_LICENSE_PLATE; } else if (!LicensePlateValidator.validate(licensePlate)) { Toast.makeText(getContext(), R.string.bus_selection_warning_plate, Toast.LENGTH_SHORT) .show(); return; } } else { Toast.makeText(getContext(), R.string.bus_selection_warning_service, Toast.LENGTH_SHORT).show(); return; } final Bus bus = new Bus(Util.formatServiceName(service), licensePlate); InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(v.getWindowToken(), 0); Log.d("BusSelectionDialog", "hiding soft input"); Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { BusSelectionDialog.this.getActivity().runOnUiThread(new Runnable() { @Override public void run() { dialog.cancel(); listener.onPositiveClick(bus); } }); } }, 500); //dialog.cancel(); // TODO(aantoine): This call is to quick, some times the keyboard is not // out of the window when de sliding panel shows up. //listener.onPositiveClick(bus); } }); /* set cancel button to close dialog */ dialog_view.findViewById(R.id.close_dialog).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { dialog.cancel(); listener.onNegativeClick(); } }); ((Button) dialog_view.findViewById(R.id.close_dialog)).setTypeface(iconTypeface); dialog.setCanceledOnTouchOutside(false); return dialog; }
From source file:org.rm3l.ddwrt.mgmt.RouterManagementActivity.java
@Override public void onClick(@Nullable View view) { if (view == null) { return;// ww w .ja v a 2s . com } if (view.getId() == R.id.router_list_add) { this.openAddRouterForm(); } else if (view.getId() == R.id.container_list_item) { // item click final int idx = mRecyclerView.getChildPosition(view); final RouterListRecycleViewAdapter adapter = (RouterListRecycleViewAdapter) mAdapter; if (actionMode != null) { final int previousSelectedItemCount = adapter.getSelectedItemCount(); myToggleSelection(idx); //Set background color, depending on whether this is a selection or a de-selection final int currentSelectedItemCount = adapter.getSelectedItemCount(); if (currentSelectedItemCount == previousSelectedItemCount - 1) { //De-selection: remove background view.setBackgroundResource(android.R.color.transparent); } else if (currentSelectedItemCount == previousSelectedItemCount + 1) { //Selection: apply background view.setBackgroundResource(android.R.color.background_light); } //other cases should not occur (as this is a single selection) //Now hide ActionMode if selected items count falls to 0 if (currentSelectedItemCount == 0) { actionMode.finish(); } return; } final AlertDialog alertDialog = Utils.buildAlertDialog(this, null, "Loading...", false, false); alertDialog.show(); ((TextView) alertDialog.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_HORIZONTAL); new Handler().postDelayed(new Runnable() { @Override public void run() { //No action mode - normal mode => open up main activity for this router final List<Router> routersList = adapter.getRoutersList(); final Router router; if (idx < 0 || idx >= routersList.size() || (router = routersList.get(idx)) == null) { Crouton.makeText(RouterManagementActivity.this, "Unknown router - please refresh list or add a new one.", Style.ALERT).show(); return; } final Intent ddWrtMainIntent = new Intent(RouterManagementActivity.this, DDWRTMainActivity.class); ddWrtMainIntent.putExtra(ROUTER_SELECTED, router.getUuid()); RouterManagementActivity.this.startActivity(ddWrtMainIntent); alertDialog.cancel(); } }, 2000); } }
From source file:dude.morrildl.weatherport.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // this gets a little hairy, but each class is too trivial to bother // moving to its own file; but together they add up to be a little // irritating. So it goes. // first we need to inflate the View for the Action Bar operations, and // then set click handlers on them. This one is is the add-new-airport // dialog,/*from w w w . j av a 2 s. c o m*/ // which cascades a bit getMenuInflater().inflate(R.menu.main, menu); menu.findItem(R.id.action_add).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { // yo dawg, I hurd you like callbacks LayoutInflater inflater = MainActivity.this.getLayoutInflater(); View v = inflater.inflate(R.layout.dialog, null); final EditText et = (EditText) v.findViewById(R.id.dialog_input); // this is the // "enter a new airport code to add to the list" dialog AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); final AlertDialog dialog = builder.setTitle(R.string.dialog_title).setIcon(R.drawable.ic_launcher) .setView(v).setPositiveButton(R.string.dialog_pos, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { String newAirport = et.getText().toString().toUpperCase(); SharedPreferences prefs = MainActivity.this.getSharedPreferences("prefs", Context.MODE_PRIVATE); Set<String> currentList = prefs.getStringSet("airports", new HashSet<String>()); HashSet<String> newSet = new HashSet<String>(); newSet.addAll(currentList); newSet.add(newAirport); prefs.edit().putStringSet("airports", newSet).commit(); ArrayList<String> newList = new ArrayList<String>(); newList.addAll(newSet); Collections.sort(newList); adapter.clear(); adapter.addAll(newList); // I N C E P T I O N } }).setNegativeButton(R.string.dialog_neg, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }).create(); et.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean focused) { if (focused) { dialog.getWindow() .setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); } } }); dialog.show(); return true; } }); // ...and this one launches our FOSS compliance screen. menu.findItem(R.id.action_settings).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { Intent intent = new Intent(); intent.setClass(MainActivity.this, AboutActivity.class); MainActivity.this.startActivity(intent); return true; } }); return true; }
From source file:mediachooser.activity.HomeFragmentActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == MediaChooserConstants.CAPTURE_VIDEO_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show();//w w w .ja v a 2 s.c om handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); // VideoFragment videoFragment = (VideoFragment) fragmentManager.findFragmentByTag("tab2"); // // if(videoFragment == null){ // VideoFragment newVideoFragment = new VideoFragment(); // newVideoFragment.addItem(fileUriString); // // }else{ // videoFragment.addItem(fileUriString); // } alertDialog.cancel(); } }, 5000); } else if (resultCode == RESULT_CANCELED) { // User cancelled the video capture } else { // Video capture failed, advise user } } else if (requestCode == MediaChooserConstants.CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, fileUri)); final AlertDialog alertDialog = MediaChooserConstants.getDialog(HomeFragmentActivity.this).create(); alertDialog.show(); handler.postDelayed(new Runnable() { @Override public void run() { //Do something after 5000ms String fileUriString = fileUri.toString().replaceFirst("file:///", "/").trim(); android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager(); ImageFragment imageFragment = (ImageFragment) fragmentManager.findFragmentByTag("tab1"); if (imageFragment == null) { ImageFragment newImageFragment = new ImageFragment(); newImageFragment.addItem(fileUriString); } else { imageFragment.addItem(fileUriString); } alertDialog.cancel(); } }, 5000); } } }
From source file:com.github.akinaru.hcidebugger.activity.HciDebuggerActivity.java
/** * setup a filter/*from www .j a va 2s . c o m*/ */ private void filter() { Log.v(TAG, "setting filter"); final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(HciDebuggerActivity.this); LayoutInflater inflater = getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.filter_dialog, null); dialogBuilder.setView(dialogView); //packet type setupSpinnerAdapter(R.array.packet_type_array, dialogView, R.id.packet_type_filter, filters.getPacketTypeFilter()); //event type setupSpinnerAdapter(R.array.event_type_array, dialogView, R.id.event_type_filter, filters.getEventTypeFilter()); //ogf setupSpinnerAdapter(R.array.ogf_array, dialogView, R.id.cmd_ogf_filter, filters.getOgfFilter()); //subevent_type_filter setupSpinnerAdapter(R.array.subevent_array, dialogView, R.id.subevent_type_filter, filters.getSubeventFilter()); EditText addressText = (EditText) dialogView.findViewById(R.id.device_address_edit); addressText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { filters.setAddress(s.toString()); SharedPreferences.Editor editor = prefs.edit(); editor.putString(Constants.PREFERENCES_ADVERTISING_ADDR, s.toString()); editor.commit(); } @Override public void afterTextChanged(Editable s) { } }); addressText.setText(filters.getAdvertizingAddr()); final AlertDialog alertDialog = dialogBuilder.create(); final Button button_withdraw_filter = (Button) dialogView.findViewById(R.id.button_withdraw_filter); if (isFiltered) button_withdraw_filter.setVisibility(View.VISIBLE); else button_withdraw_filter.setVisibility(View.GONE); button_withdraw_filter.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { isFiltered = false; packetAdapter.setPacketList(packetList); notifyAdapter(); alertDialog.cancel(); alertDialog.dismiss(); packetFilteredList.clear(); } }); Button button_apply = (Button) dialogView.findViewById(R.id.button_apply_filter); button_apply.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Spinner packet_type_filter = (Spinner) dialogView.findViewById(R.id.packet_type_filter); Spinner ogf_filter = (Spinner) dialogView.findViewById(R.id.cmd_ogf_filter); Spinner event_type_filter = (Spinner) dialogView.findViewById(R.id.event_type_filter); Spinner subevent_type_filter = (Spinner) dialogView.findViewById(R.id.subevent_type_filter); EditText device_address_edit = (EditText) dialogView.findViewById(R.id.device_address_edit); filters = new Filters(HciDebuggerActivity.this, packet_type_filter.getSelectedItem().toString(), event_type_filter.getSelectedItem().toString(), ogf_filter.getSelectedItem().toString(), subevent_type_filter.getSelectedItem().toString(), device_address_edit.getText().toString()); packetFilteredList = new ArrayList<Packet>(); for (int i = 0; i < packetList.size(); i++) { if (matchFilter(packetList.get(i))) { packetFilteredList.add(packetList.get(i)); } } isFiltered = true; packetAdapter.setPacketList(packetFilteredList); notifyAdapter(); alertDialog.cancel(); alertDialog.dismiss(); } }); Button button_cancel = (Button) dialogView.findViewById(R.id.button_cancel_filter); button_cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.cancel(); alertDialog.dismiss(); } }); alertDialog.show(); }
From source file:com.hx.hxchat.activity.ChatHistoryFragment.java
/** * //from w w w . ja va 2 s . c o m * @param title * @param emContact */ private void showMyDialog(String title, final ChatHistoryAdapter adapter, final int position) { final AlertDialog dlg = new AlertDialog.Builder(context).create(); dlg.show(); Window window = dlg.getWindow(); // ??,shrew_exit_dialog.xmlview window.setContentView(R.layout.alertdialog); window.findViewById(R.id.ll_title).setVisibility(View.VISIBLE); TextView tv_title = (TextView) window.findViewById(R.id.tv_title); tv_title.setText(title); TextView tv_content1 = (TextView) window.findViewById(R.id.tv_content1); final String username = adapter.getItem(position).getUsername(); // ?? if (topMap.containsKey(username)) { tv_content1.setText("?"); } else { tv_content1.setText("?"); } tv_content1.setOnClickListener(new View.OnClickListener() { @SuppressLint("SdCardPath") public void onClick(View v) { if (topMap.containsKey(username)) { topMap.remove(username); TopUserDao topUserDao = new TopUserDao(context); topUserDao.deleteTopUser(username); } else { TopUser topUser = new TopUser(); topUser.setTime(System.currentTimeMillis()); // 1--- topUser.setType(1); topUser.setUserName(username); Map<String, TopUser> map = new HashMap<String, TopUser>(); map.put(adapter.getItem(position).getUsername(), topUser); topMap.putAll(map); TopUserDao topUserDao = new TopUserDao(context); topUserDao.saveTopUser(topUser); } refresh(); dlg.cancel(); } }); TextView tv_content2 = (TextView) window.findViewById(R.id.tv_content2); tv_content2.setText("?"); tv_content2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { EMContact tobeDeleteUser = adapter.getItem(position); EMChatManager.getInstance().deleteConversation(adapter.getItem(position).getUsername()); InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(context); inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername()); BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername()); adapter.remove(tobeDeleteUser); adapter.notifyDataSetChanged(); // ((MainActivity) context).homefragment.refresh(); // boolean isGroup = false; // // // if (tobeDeleteUser instanceof EMGroup) // isGroup = true; // // // ? // boolean deleteConversation = EMChatManager.getInstance().deleteConversation(tobeDeleteUser.getUsername()); // InviteMessgeDao inviteMessgeDao = new InviteMessgeDao(getActivity()); // inviteMessgeDao.deleteMessage(tobeDeleteUser.getUsername()); // // BaseApplication.getApplication().GetLinkerDao().deleteContact(tobeDeleteUser.getUsername()); // adapter.remove(tobeDeleteUser); // adapter.notifyDataSetChanged(); // // // ? // // TODO // // ((MainActivity) getActivity()).updateUnreadLabel(); // // // dlg.cancel(); } }); }
From source file:com.hybris.mobile.app.commerce.adapter.AccountPaymentAdapter.java
@Override public View getView(final int position, View convertView, ViewGroup parent) { View rowView;//from w w w . j av a 2s .co m if (convertView == null) { LayoutInflater inflater = (LayoutInflater) getContext() .getSystemService(Context.LAYOUT_INFLATER_SERVICE); rowView = inflater.inflate(R.layout.item_payment_details, parent, false); rowView.setTag(new PaymentViewHolder(rowView, position)); } else { rowView = convertView; } PaymentViewHolder mPaymentViewHolder = (PaymentViewHolder) rowView.getTag(); final PaymentDetails paymentDetails = getItem(position); if (paymentDetails != null) { mPaymentViewHolder.paymentCardholderName.setText(paymentDetails.getAccountHolderName()); mPaymentViewHolder.cardDetails .setText(paymentDetails.getCardType().getName() + "\n" + paymentDetails.getCardNumber() + "\n" + paymentDetails.getExpiryMonth() + "/" + paymentDetails.getExpiryYear()); if (paymentDetails.getBillingAddress() != null) { mPaymentViewHolder.billingAddress .setText(StringUtils.isNotBlank(paymentDetails.getBillingAddress().getFormattedAddress()) ? paymentDetails.getBillingAddress().getFormattedAddress() : paymentDetails.getBillingAddress().getLine1() + " " + paymentDetails.getBillingAddress().getLine2() + ",\n " + paymentDetails.getBillingAddress().getTown() + " " + paymentDetails.getBillingAddress().getPostalCode()); } mPaymentViewHolder.paymentDefaultImageView.setVisibility(View.GONE); mPaymentViewHolder.paymentSetDefaultButton.setVisibility(View.INVISIBLE); mPaymentViewHolder.paymentDefaultImageView.setVisibility(position == 0 ? View.VISIBLE : View.INVISIBLE); //mPaymentViewHolder.paymentSetDefaultButton.setVisibility(position == 0 ? View.INVISIBLE : View.VISIBLE); mPaymentViewHolder.paymentDeleteButton.setVisibility(View.VISIBLE); mPaymentViewHolder.paymentSetDefaultButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setDefaultPayment(paymentDetails); Alert.showSuccess(getContext(), getContext().getString(R.string.payment_default_updated_message)); } }); mPaymentViewHolder.paymentDetailsLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mOnPaymentSelectedListener.onPaymentSelected(paymentDetails); } }); } mPaymentViewHolder.paymentDeleteButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog dialog; AlertDialog.Builder builder = new AlertDialog.Builder(getContext()); builder.setMessage(R.string.payment_delete_message) .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { QueryPayment queryPayment = new QueryPayment(); queryPayment.setPaymentDetailsId(paymentDetails.getId()); CommerceApplication.getContentServiceHelper() .deleteUserPaymentDetails(new ResponseReceiverEmpty() { @Override public void onResponse(Response<EmptyResponse> response) { Alert.showSuccess(getContext(), getContext() .getString(R.string.payment_delete_success_message)); if (position < mPaymentList.size()) { mPaymentList.remove(position); } mOnPaymentSelectedListener.onPaymentListRefreshed(); //Default is the first but if deleted select the next one as default if (mPaymentList != null && !mPaymentList.isEmpty() && position == 0) { setDefaultPayment(mPaymentList.get(0)); } } @Override public void onError(Response<ErrorList> response) { } }, null, queryPayment, null, false, null, null); dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }); dialog = builder.create(); dialog.show(); } }); return rowView; }