EDIT~ Solution found and in my response below (last response for now) but I can't mark it as the answer for question until two days from now. In the meantime, I'll leave this edit here until I can mark it correct.
Where the dialog is called:
public OnClickListener fieldListener = new OnClickListener() {
public void onClick(View v) {
FragmentManager fm = getSupportFragmentManager();
switch (v.getId()) {
case (0) :
ChooseDialog ageDialog = new ChooseDialog("Age", ageEditText, act);
ageDialog.show(fm, "fragment_edit_name");
The Dialog:
public class ChooseDialog extends DialogFragment implements DialogInterface.OnClickListener, OnMultiChoiceClickListener {
public Dialog onCreateDialog(Bundle savedInstanceState) {
LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View dialogLayout = inflater.inflate(R.layout.dialog, null);
AlertDialog.Builder builder;
switch (editText.getId()) {
case (0) :
ListView list = (ListView) dialogLayout.findViewById(R.id.listView1);
list.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist,
activity.getResources().getStringArray(R.array.ageArray)));
list.setBackgroundColor(00000000);
builder = new AlertDialog.Builder(activity);
builder.setTitle(type);
builder.setNegativeButton("Cancel", this);
builder.setView(dialogLayout);
/* builder.setAdapter(new ArrayAdapter<String>(activity, R.layout.dialoglist,
activity.getResources().getStringArray(R.array.ageArray)),
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
editText.setText(activity.getResources().getStringArray(R.array.ageArray)[which]);
}}
);*/
return builder.create();
Dialog.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listView1"
android:background="#00000000"
android:cacheColorHint="#00000000"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
DialogList.xml (just the textview for the adapter):
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="6dip"
android:textColor="@color/androidBlue"
android:paddingRight="10dip"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />