2017-10-18 150 views
0

我正在陣列適配器對話框中,我需要顯示兩個電話號碼。問題是我的號碼沒有顯示在那裏,只顯示空白空間,但是當我點擊任何空間時,它顯示我的號碼在那裏,但沒有顯示。文本沒有顯示在陣列適配器對話框

我的代碼如下:

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(); 

} 

enter image description here

+1

檢查'array'大小和打印請 –

+0

@IntelliJAmiya感謝您的回覆。我的數組大小是2,數字是:1234,5678. –

+1

https://stackoverflow.com/questions/43202985/android-spinner-items-not-showing –

回答

0

解決了@IntelliJ阿米亞·給我的問題,指導。我正在做下面的機制來做到這一點。

方法,其中我打電話此對話框:

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; 
     } 

    }