@Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); onAccountSelected(accountAdapter.getItem(which)); } };
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); final Bundle args = getArguments(); final AccountListFilter filter = (AccountListFilter) args.getSerializable(KEY_LIST_FILTER); final AccountsListAdapter accountAdapter = new AccountsListAdapter(builder.getContext(), filter); accountAdapter.setCustomLayout(R.layout.account_selector_list_item_condensed); final DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); onAccountSelected(accountAdapter.getItem(which)); } }; builder.setTitle(args.getInt(KEY_TITLE_RES_ID)); builder.setSingleChoiceItems(accountAdapter, 0, clickListener); final AlertDialog result = builder.create(); return result; }
/** * @param currentAccount the Account currently selected by the user, which should come * first in the list. Can be null. */ public AccountsListAdapter(Context context, AccountListFilter accountListFilter, AccountWithDataSet currentAccount) { mContext = context; mAccountTypes = AccountTypeManager.getInstance(context); mAccounts = getAccounts(accountListFilter); if (currentAccount != null && !mAccounts.isEmpty() && !mAccounts.get(0).equals(currentAccount) && mAccounts.remove(currentAccount)) { mAccounts.add(0, currentAccount); } mInflater = LayoutInflater.from(context); }