Code example for AlertDialog.Builder

Methods: setAdapter, setPositiveButton

0
			throw new IllegalStateException("TemaWarnaPreference requires an entries array and an entryValues array."); //$NON-NLS-1$
		} 
 
		mClickedDialogEntryIndex = getValueIndex();
 
		builder.setAdapter(new BaseAdapter() {
			@Override public View getView(int position, View convertView, ViewGroup parent) {
				CheckedTextView res = (CheckedTextView) convertView;
				if (convertView == null) {
					res = (CheckedTextView) LayoutInflater.from(getContext()).inflate(android.R.layout.select_dialog_singlechoice, null);
				} 
 
				CharSequence value = entryValues[position];
				int[] w = pisahWarna(value);
 
				SpannableStringBuilder sb = new SpannableStringBuilder();
 
				// no ayat 
				String s1 = String.valueOf(position + 1) + " "; //$NON-NLS-1$
				sb.append(s1);
				sb.setSpan(new ForegroundColorSpan(w[2]), 0, s1.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
				// nama 
				String s2 = entries[position].toString();
				sb.append(s2);
				sb.setSpan(new ForegroundColorSpan(w[0]), s1.length(), s1.length() + s2.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
 
				res.setText(sb);
				res.setBackgroundColor(w[1]);
 
				res.setChecked(position == mClickedDialogEntryIndex);
 
				return res;
			} 
 
			@Override public long getItemId(int position) {
				return position;
			} 
 
			@Override public Object getItem(int position) {
				return null; 
			} 
 
			@Override public int getCount() { 
				return entryValues.length;
			} 
		}, new DialogInterface.OnClickListener() {
			@Override public void onClick(DialogInterface dialog, int which) {
				mClickedDialogEntryIndex = which;
 
				/* 
				 * Clicking on an item simulates the positive button 
				 * click, and dismisses the dialog. 
				 */ 
				ColorThemePreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
				dialog.dismiss();
			} 
		}); 
 
		/* 
		 * The typical interaction for list-based dialogs is to have 
		 * click-on-an-item dismiss the dialog instead of the user having to 
		 * press 'Ok'. 
		 */ 
		builder.setPositiveButton(null, null);
	} 
 
	@Override protected void onDialogClosed(boolean positiveResult) {
		super.onDialogClosed(positiveResult);