Code
Button mButton1;
String mDefaultFont1;
SharedPreferences mSharedPreferences1;
SharedPreferences.Editor editor1;
mButton1 = (Button)findViewById(R.id.buttontextfontsent);
mSharedPreferences1 = PreferenceManager.getDefaultSharedPreferences(this);
mDefaultFont1 = mSharedPreferences1.getString("Default_Font1","Normal");
mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
mButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String[] list = new String[]{"Normal", "Bold", "Italic", "Bold ITalic"};
AlertDialog.Builder builder = new AlertDialog.Builder(CustomizeFont.this);
builder.setTitle("Make your selection");
builder.setItems(list, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item==0) mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
if (item==1) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD);
if (item==2) mButton1.setTypeface(mButton1.getTypeface(),Typeface.ITALIC);
if (item==3) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD_ITALIC);
editor1 = PreferenceManager.getDefaultSharedPreferences(CustomizeFont.this).edit();
editor1.putString("Default_Font1", String.valueOf(item));
editor1.apply();
}
});
builder.show();
}
});
I can change the font but when i restart the activity it goes back to the original normal font... the problem is because of this line mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
I need to set the TypeFace.NORMAL to Default_Font1 But not accepting... what should I do?
I need to set the textview to Default_Font1 But not accepting... what should I do?
You need to setTypeface in your button based on you values getting from SharedPreferences
SAMPLE CODE
mDefaultFont1 = mSharedPreferences1.getString("Default_Font1","0");
if (mDefaultFont1.equals("0")) {
mButton1.setTypeface(mButton1.getTypeface(), Typeface.NORMAL);
} else if (mDefaultFont1.equals("1")) {
mButton1.setTypeface(mButton1.getTypeface(), Typeface.BOLD);
} else if (mDefaultFont1.equals("2")) {
mButton1.setTypeface(mButton1.getTypeface(), Typeface.ITALIC);
} else if (mDefaultFont1.equals("3")) {
mButton1.setTypeface(mButton1.getTypeface(), Typeface.BOLD_ITALIC);
}
mButton1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String[] list = new String[]{"Normal", "Bold", "Italic", "Bold ITalic"};
AlertDialog.Builder builder = new AlertDialog.Builder(CustomizeFont.this);
builder.setTitle("Make your selection");
builder.setItems(list, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
if (item==0) mButton1.setTypeface(null);
if (item==1) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD);
if (item==2) mButton1.setTypeface(mButton1.getTypeface(),Typeface.ITALIC);
if (item==3) mButton1.setTypeface(mButton1.getTypeface(),Typeface.BOLD_ITALIC);
editor1 = PreferenceManager.getDefaultSharedPreferences(CustomizeFont.this).edit();
editor1.putString("Default_Font1", String.valueOf(item));
editor1.apply();
}
});
builder.show();
}
});
try this .
editor.putInt("fontCode",mButton1.getTypeFace().getStyle());
and then use it as normal shared prefrence
mDefaultFont1 = mSharedPreferences1.getString("Default_Font1","Normal");
mButton1.setTypeface(mButton1.getTypeface(),Typeface.NORMAL);
This logic is completely wrong, keep in mind that you're saving int values in preferences (0, 1, 2, 3), but first you load it as if it was string with default value "normal".
In the second line you're setting the typeface for the button, but taking current typeface from same button, so what you get? No change.
Instead of that, I suggest something like this:
mDefaultFont1 = mSharedPreferences1.getInt("Default_Font1",0);
mButton1.setTypeface(mDefaultFont1);
And save the preference like this:
public void onClick(DialogInterface dialog, int item) {
int defaultTypeface = 0;
if (item==0) defaultTypeface = Typeface.NORMAL;
if (item==1) defaultTypeface = Typeface.BOLD;
if (item==2) defaultTypeface = Typeface.ITALIC;
if (item==3) defaultTypeface = Typeface.BOLD_ITALIC;
mButton1.setTypeface(defaultTypeface);
editor1 = PreferenceManager.getDefaultSharedPreferences(CustomizeFont.this).edit();
editor1.putInt("Default_Font1", defaultTypeface);
editor1.apply();
}
Note, my code might be bit wrong, since I did write it from memory and didn't check if it's really fine.
Related
Here is my code it is working please tell me code button for "no thanks" if user tap on this button then dialog box never show at all
public class MainActivity extends Activity {
Button btnRegId;
EditText etRegId;
String regID;
GoogleCloudMessaging gcm;
String regid,url;
//String PROJECT_NUMBER = "90787073097";
String PROJECT_NUMBER = "440085976573";
String android_id,version,ver;
ImageView mega4,todayTips,latstnews,sportquiz,tipister;
TextView txtname;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// etRegId = (EditText) findViewById(R.id.edtvID);
//********************For Rating APP **********************
SharedPreferences sharedPrefs = MainActivity.this.getSharedPreferences("RATER", 0);
SharedPreferences.Editor prefsEditor = sharedPrefs.edit();
long time = sharedPrefs.getLong("displayedTime", 0);
if (time < System.currentTimeMillis() - 259200000) {
displayDialog();
prefsEditor.putLong("displayedTime", System.currentTimeMillis()).commit();
}
}
//dialog box Function for rating app.
private void displayDialog() {
// TODO Auto-generated method stub
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
switch (which){
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
Intent in = new Intent(android.content.Intent.ACTION_VIEW);
in.setData(Uri.parse(url));
startActivity(in);
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Rate This App");
builder.setMessage("You really seem to like this app, "
+"since you have already used it %totalLaunchCount% times! "
+"It would be great if you took a moment to rate it.")
.setPositiveButton("Rate Now", dialogClickListener)
.setNegativeButton("Latter", dialogClickListener)
.setNeutralButton("No,thanks", dialogClickListener).show();
}
//End dialog box Function for rating app.
}
Here is my code actually i want to implement app rating dialog box in application that should display once in three day
You have to initialize your SharedPreferences and Editor Object like this:
SharedPreferences prefs = mContext.getSharedPreferences("RATER", 0);
SharedPreferences.Editor editor = prefs.edit();
UPDATE
Just save a boolean when user cliks on no thanks and check it before showing the dialog. If it true then it will not show the dialog box.
//Saving a boolean on no thanks button click
SharedPreferences prefs = mContext.getSharedPreferences("RATER", 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("NO THANKS", true));
editor.apply();
Access it in your dialog showing method.
SharedPreferences prefs = mContext.getSharedPreferences("RATER", 0);
if (prefs.getBoolean("NO THANKS", false)) {
return;
}else {
SharedPreferences.Editor editor = prefs.edit();
//YOUR CODE TO SHOW DIALOG
editor.apply();
}
FULL CODE
public class MainActivity extends Activity {
Button btnRegId;
EditText etRegId;
String regID;
GoogleCloudMessaging gcm;
String regid, url;
//String PROJECT_NUMBER = "90787073097";
String PROJECT_NUMBER = "440085976573";
String android_id, version, ver;
ImageView mega4, todayTips, latstnews, sportquiz, tipister;
TextView txtname;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// etRegId = (EditText) findViewById(R.id.edtvID);
//********************For Rating APP **********************
SharedPreferences sharedPrefs = MainActivity.this.getSharedPreferences("RATER", 0);
if (sharedPrefs.getBoolean("NO THANKS", false)) {
return;
} else {
SharedPreferences.Editor prefsEditor = sharedPrefs.edit();
//YOUR CODE TO SHOW DIALOG
long time = sharedPrefs.getLong("displayedTime", 0);
if (time < System.currentTimeMillis() - 259200000) {
displayDialog();
prefsEditor.putLong("displayedTime", System.currentTimeMillis()).commit();
}
prefsEditor.apply();
}
}
//dialog box Function for rating app.
private void displayDialog() {
// TODO Auto-generated method stub
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
//Yes button clicked
Intent in = new Intent(android.content.Intent.ACTION_VIEW);
in.setData(Uri.parse(url));
startActivity(in);
break;
case DialogInterface.BUTTON_NEGATIVE:
//No button clicked
//Saving a boolean on no thanks button click
SharedPreferences prefs = MainActivity.this.getSharedPreferences("RATER", 0);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("NO THANKS", true);
editor.apply();
break;
}
}
};
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle("Rate This App");
builder.setMessage("You really seem to like this app, "
+ "since you have already used it %totalLaunchCount% times! "
+ "It would be great if you took a moment to rate it.")
.setPositiveButton("Rate Now", dialogClickListener)
.setNegativeButton("Latter", dialogClickListener)
.setNeutralButton("No,thanks", dialogClickListener).show();
}
//End dialog box Function for rating app.
}
here is my code as a function for 10 days.
I made the initial value current time - 11 days to make sure it will run first time app launches
public void dialogEvery10Days() {
Long duration = getSharedPreferences("PREFERENCE", MODE_PRIVATE).getLong("duration", System.currentTimeMillis()-TimeUnit.DAYS.toMillis(11));
if (System.currentTimeMillis()-duration > TimeUnit.DAYS.toMillis(10)) {
// inflateDialog is a function containing the functionality of popping up the dialog
Dialog dialog = inflateDialog(R.layout.dialog_layout);
getSharedPreferences("PREFERENCE", MODE_PRIVATE)
.edit()
.putLong("duration", System.currentTimeMillis())
.apply();
}
}
I have this code for showing list of languages for download:
public void onCreateDialog(ArrayList<String>fullLangArray, final ArrayList<String>codeLangArray) {
final String[] items = fullLangArray.toArray(new String[fullLangArray.size()]);
final ArrayList mSelectedItems = new ArrayList();
AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
// Set the dialog title
builder.setTitle("Updates...")
.setMultiChoiceItems(items, null,
new DialogInterface.OnMultiChoiceClickListener() {
#Override
public void onClick(DialogInterface dialog, int indexSelected,
boolean isChecked) {
if (isChecked) {
mSelectedItems.add(Utils.SERVER_ADDRESS + "/" + codeLangArray.get(indexSelected) + ".zip");
} else if (mSelectedItems.contains(indexSelected)) {
mSelectedItems.remove(Integer.valueOf(indexSelected));
}
}
})
.setPositiveButton("Download", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
DownloadTask downloadTask = new DownloadTask(MainActivity.this);
downloadTask.execute(mSelectedItems.toString());
}
})
.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int id) {
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
I want to make a one item of a checkbox is checked and "disabled" like in a photo (Option 3) when AlertDialog is loaded.
Can you help me how to do it?
You can check the checkbox by using the setChecked() method which boolean value as parameter.
Example:
option1.setChecked(true);
and also uncheck it using
option2.setChecked(false);
If you want to set it to checked and disabled you have use setEnabled() which takes boolean as it's parameters.
Example.
option3.setChecked(true);
option3.setEnabled(false);
This will disable your checkbox and even check it. I hope this was helpful. ThankYou.
For setting Opacity
mSelectedItems.getBackground().setAlpha(128);
Where the INT ranges from 0 (fully transparent) to 255 (fully opaque).
For setChecked item
mSelectedItems.setChecked(true);
Disable checking
mSelectedItems.setEnabled(false)
I've got an inputDialog, which allows for some text inputs. On clicking save, the inputDialog checks if the entered text is already available (to prevent double entries). If this is the case, a new AlertDialog is created, simply stating "The value you entered already exists", with just an "Ok" button to dismiss this AlertDialog. This all works.
I would like to have the inputDialog pop back up again, after dismissing the AlertDialog, with the values that were entered by the user before still in the editText fields.
I'm not expecting any problems on getting those values back in the editText fields (Store them in a variable on clicking save, if the double entry error occurs, set those variables on the editText's. If I'm doing this in a stupid way, please let me know).
I am however having trouble with getting the first (inputDialog) dialog to come back. The code you see below is the code for my inputDialog fragment (The code is simplified, so if something seems to be missing, it probably is. Let me know, so I can add it back in.)
So, to repeat myself: How can I return to the previous dialog after dismissing the second one?
StuffManagerInputDialogFragment.java:
public class StuffManagerInputDialogFragment extends DialogFragment {
EditText nameInputField;
EditText tagInputField;
DBHandler dbHandler;
StuffManagerFragment f = new StuffManagerFragment();
#Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = getActivity().getLayoutInflater();
final View v_iew = inflater.inflate(R.layout.fragment_inputdialog, null);
nameInputField = (EditText) v_iew.findViewById(R.id.inputdialogname);
tagInputField = (EditText) v_iew.findViewById(R.id.inputdialogtag);
dbHandler = new DBHandler(getActivity(), null, null, 1);
final MainActivity ma = (MainActivity) getActivity();
final AlertDialog.Builder newLinkDialog = new AlertDialog.Builder(getActivity());
newLinkDialog.setView(v_iew)
.setTitle("New Link")
.setPositiveButton("Save", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
String nameInputFieldText = nameInputField.getText().toString();
String tagInputFieldText = tagInputField.getText().toString();
ArrayList<String> nameArray = dbHandler.nameArrayMethod();
ArrayList<String> tagArray = dbHandler.tagArrayMethod();
NavigationView navigationView = (NavigationView) getActivity().findViewById(R.id.nav_view);
Menu menu = navigationView.getMenu();
if (nameArray.contains(nameInputFieldText) || tagArray.contains(tagInputFieldText)) {
if (nameArray.contains(nameInputFieldText) && tagArray.contains(tagInputFieldText)) {
AlertDialog.Builder errorBoth = new AlertDialog.Builder(getActivity())
.setTitle("Error")
.setMessage("The name and tag you entered are already in use.")
.setIcon(R.drawable.ic_error_black)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
//Return to previous dialog here
}
});
errorBoth.show();
}
} else {
dbHandler.addLink(nameInputFieldText, tagInputFieldText);
nameArray = dbHandler.nameArrayMethod();
int nameArraySize = (nameArray.size() - 1);
MenuItem item = menu.add(R.id.group1, nameArraySize, 1, nameArray.get(nameArraySize));
Toast.makeText(getContext(), "'" + nameInputFieldText + " - " + tagInputFieldText + "' link saved.", Toast.LENGTH_SHORT).show();
ma.addSMVFFragments();
f.hideDeleteAllButton = false;
getActivity().invalidateOptionsMenu();
}
}
})
.setNegativeButton("Cancel", null);
return newLinkDialog.create();
}
}
A better solution is to have a dialog fragment for your input layout, and that dialog fragment would display an AlertDialog on OK if the text validation fails. The input dialog fragment would not dismiss in this case, it will remain in the background so when you dismiss the alert dialog to tell the user the input is invalid, you return to the input dialog as it was.
To prevent the dialog fragment from dismissing on OK you would override onStart and get a reference to the OK button and set the listener there, like this:
#Override
public void onStart() {
super.onStart();
AlertDialog alertDialog = (AlertDialog) getDialog();
if (alertDialog != null) {
mOKButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
mOkButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (field OK) {
// save data
dismiss();
} else {
// show error dialog
}
}
});
}
}
Hi I've gone through all of the different linkify tutorials I could find but none of them work here is my current code:
final SpannableString s = new SpannableString("Please send any questions to email#fake.com");
Linkify.addLinks(s, Linkify.EMAIL_ADDRESSES);
AlertDialog.Builder builder = new AlertDialog.Builder(Activity.this);
builder.setTitle("Warning!")
.setMessage(s)
.setCancelable(false)
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Activity.this.finish();
}
}).show();
However when I actually run the app it shows the text like blue and underlined as if it were linked but selecting the text doesn't prompt to open the email app. I've also tried with urls and the browser doesn't work is there something that's missing?
Thanks for any help.
In order to have a clickable area on dialog you need to use TextView (View) and set autoLink=all in layout file or invoke setAutoLinkMask() method from within the code.
final SpannableString s = new SpannableString("Please send any questions to email#fake.com");
//added a TextView
final TextView tx1=new TextView(this);
tx1.setText(s);
tx1.setAutoLinkMask(RESULT_OK);
tx1.setMovementMethod(LinkMovementMethod.getInstance());
Linkify.addLinks(s, Linkify.EMAIL_ADDRESSES);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Warning!")
.setCancelable(false)
.setPositiveButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
}
})
.setNegativeButton("Decline", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setView(tx1)
.show();
Here's Kotlin in case it's helpful:
val s = SpannableString(getString(R.string.actions_list_info_button_body))
val tx1 = TextView(context!!)
tx1.text = s
tx1.autoLinkMask = RESULT_OK
tx1.movementMethod = LinkMovementMethod.getInstance()
The rest is the same.
The result likely will not look great so you probably will want to add some padding as well:
// Adjust Padding to dp
val scale: Float = resources.displayMetrics.density
val dpAsPixels: Int = (25 * scale + 0.5f).toInt()
text.setPadding(dpAsPixels,20,dpAsPixels,0)
Alternatively, you can reuse the TextView created.
AlertDialog.Builder builder;
builder.setMessage(R.string.yourMessage);
Dialog dialog = builder.create();
dialog.setOnShowListener(d -> {
TextView text = dialog.getWindow().findViewById(android.R.id.message);
text.setAutoLinkMask(Linkify.ALL);
text.setMovementMethod(LinkMovementMethod.getInstance());
});
I have this .xml file with countries and their countrycodes in them. This is how it looks like:
<?xml version="1.0" encoding="UTF-8"?>
<landen>
<land>
<naam>Afghanistan</naam>
<code>AF</code>
</land>
<land>
<naam>Albani�</naam>
<code>AL</code>
</land>
<land>
<naam>Algerije</naam>
<code>DZ</code>
</land>
<land>
</landen>
Now I want people to choose one country out of an list. I though an AlertDialog would be nice to display everything.
The way i get the values out of my xml-file is like this:
protected ArrayList<Land> getLanden() {
ArrayList<Land> lijst = new ArrayList<Land>();
try {
DocumentBuilder builder =DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.parse(getAssets().open("landenlijst.xml"));
NodeList nl = doc.getElementsByTagName("land");
for (int i=0;i<nl.getLength();i++) {
Node node = nl.item(i);
Land land = new Land();
land.land = Xml.innerHtml(Xml.getChildByTagName(node, "naam"));
land.landcode = Xml.innerHtml(Xml.getChildByTagName(node, "code"));
lijst.add(land);
}
Log.d("Gabug","Klaar met parsen");
Log.d("Gabug","Landen: " + lijst);
} catch (Exception e) {
e.printStackTrace();
}
return lijst;
}
And I use this to make my AlertDialog:
public void KiesLandMenu(){
ArrayList<Land> alleLanden = getLanden();
final CharSequence[] items = alleLanden.toArray(new CharSequence[alleLanden.size()]);
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Kies land");
builder.setItems(items, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
switch (item){
case 0:
break;
case 1:
break;
case 2:
break;
}
}
});
AlertDialog alert = builder.create();
alert.show();
}
I don't know if this works as DDMS returns some bytecode or something when i Log it. And after that it Force Closes because of ArrayStoreException..
Now my question is; is this the best way to do this? if yes, how can I fix the ArrayStoreException? If no, what are better ways to let my user choose a country (a whole new view maybe)?
Furthermore, how can I register what country someone tapped?
EDIT:
I slightly changed the sample code below and I get an NullPointerException now..
public void KiesLandMenu(){
ArrayAdapter<Land> arrAdapter;
ArrayList<Land> alleLanden = getLanden();
arrAdapter = new ArrayAdapter<Land>(this, android.R.layout.simple_list_item_single_choice, alleLanden);
ListView list = (ListView)findViewById(R.layout.lijstview);
list.setAdapter(arrAdapter);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> list, View view, int position,
long id) {
Log.e("item clicked", String.valueOf(position));
}
});
}
The NullPointerException is at list.setAdapter(arrAdapter);
Make a layout with a ListView, then set that layout in your onCreate. To make the list, you can do something like:
public class RunTestProject extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main); //whatever you want your layout to be
}
// getLanden() implementation goes here
public void KiesLandMenu(){
ArrayList<Land> alleLanden = getLanden();
arrAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_single_choice, alleLanden);
Dialog dialog = new Dialog(this);
dialog.setTitle("Kies land");
dialog.setContentView(R.layout.withList); // The dialog layout
ListView list = (ListView) dialog.findViewById(android.R.id.list); //note that it's not simply findViewById
list.setAdapter(arrAdapter);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> list, View view, int position,
long id) {
Log.e("item clicked", String.valueOf(position));
}
});
dialog.show();
}
}
When the user chooses on an item, you can see in the log that the item's position in the array is shown.
Your layout file can be something like:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ListView android:id="#android:id/list"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
/>
</LinearLayout>
You could probably extend AlertDialog and give it a ListView as a view. Then bind the ListView to an ListAdapter which uses your ArrayList.
Edit:
ListView lv = new ListView(context);
ArrayAdapter aa = new ListAdapter(context, viewid, lijst);
lv.setAdapter(aa);
AlertDialog ad = new AlertDialog(context);
ad.setView(lv);
There is a bit more work than that though. You need to specify viewid which is the View representing each item in the ListView.
The sdk reference is very good you know.
new AlertDialog.Builder(this)
.setIcon(R.drawable.alert_dialog_icon)
.setTitle(R.string.alert_dialog_single_choice)
.setSingleChoiceItems(<ListAdapter> or CharaSequnce[] , 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked on a radio button do some stuff */
}
})
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked Yes so do some stuff */
}
})
.setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
/* User clicked No so do some stuff */
}
})
.create();
Note :
Please see This link to Api for Bold text mentioned below
.setSingleChoiceItems(CharacterSequnce[] , 0, new DialogInterface.OnClickListener()....
Hope this helps . Thanks :)