我正在使用阵列适配器对话框,我需要显示两个电话号码。问题是我的数字没有显示在那里,只显示空白区域,但当我点击任何一个空格时,它显示数字在那里,但它没有显示。
我的代码如下:
public void showDialog(List<String> array) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
final ArrayAdapter<String> arraylist=new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_spinner_dropdown_item, array);
builder.setSingleChoiceItems(arraylist, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
phoneCall(arraylist.getItem(item));
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.setTitle("تماس");
alert.show();
}
答案 0 :(得分:0)
解决了问题,由@IntelliJ Amiya给我的指导。我正在做以下机制。
我调用此对话框的方法:
ListAdapter adapter = new PhoneDialogAdapter(Kasab_o_karahi_activity_detail.this, array);
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
//AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style.CustomAlertDialogTheme));
builder.setTitle("تماس").setAdapter(adapter, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
String number = (adapter.getItem(item)+"");
phoneCall(number);
dialog.dismiss();
}
}).show();
自定义适配器类:
public class PhoneDialogAdapter extends ArrayAdapter<String> {
private List<Integer> images;
public PhoneDialogAdapter(Context context, List<String> items) {
super(context, android.R.layout.select_dialog_item, items);
this.images = images;
}
public PhoneDialogAdapter(Context context, String[] items) {
super(context, android.R.layout.select_dialog_item, items);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = super.getView(position, convertView, parent);
TextView textView = (TextView) view.findViewById(android.R.id.text1);
textView.setTextColor(Color.BLACK);
// textView.setCompoundDrawablesWithIntrinsicBounds(images.get(position), 0, 0, 0);
textView.setCompoundDrawablePadding((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 12, getContext().getResources().getDisplayMetrics()));
return view;
}
}