编辑〜找到解决方案并在下面的回复中(现在的最后回复),但直到两天后我才能将其标记为问题的答案。同时,我会在此处保留此编辑,直到我可以将其标记为正确为止。
调用对话框的位置:
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");
对话框:
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();
对话框.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(只是适配器的文本视图):
<?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" />