2017-12-14 26 views
0

にスピナーを移植:は、私は次のコードを使用してAlertDialogでスピナーを埋めるためにしようとしていますAlertDialog

ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, 
      android.R.layout.simple_spinner_item, providersList); 

    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 

    AlertDialog.Builder checkInDialog1 = new AlertDialog.Builder(this); 
    checkInDialog1.setView(R.layout.layout_checkin_items); 

    checkInDialog1.show(); 
    AlertDialog builder = checkInDialog1.create(); 
    Spinner checkInProviders = (Spinner) builder.findViewById(R.id.providers); 
    checkInProviders.setAdapter(dataAdapter); 

しかしbuilder.findViewByIdはcheckInProvidersにnullを返しています。私のXMLで

<Spinner 
     android:id="@+id/providers" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 

助けてください。ありがとう。

+0

あなたはポップアップでただスピナーを必要としますか? –

+0

ビューを拡張しようとしてください。 AlertDialog.Builder checkInDialog1 = new AlertDialog.Builder(this); ビューdialogView = View.inflate(this、R.layout.layout_checkin_items、null);checkInDialog1.setView(dialogView); SpinnerのcheckInProviders = dialogView.findViewById(R.id.providers); –

答えて

0

この

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); 
LayoutInflater inflater = this.getLayoutInflater(); 
final View myView = inflater.inflate(R.layout.layout_checkin_items, null); 
dialogBuilder.setView(myView);  
Spinner checkInProviders = (Spinner) myView .findViewById(R.id.providers); 
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, 
      android.R.layout.simple_spinner_item, providersList); 

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
checkInProviders.setAdapter(dataAdapter); 

は、私が思うに、この

Dialog dialog=new Dialog(this); 
dialog.setTitle("Title");  
dialog.setContentView(R.layout.layout_checkin_items); 
Spinner checkInProviders = (Spinner) dialog.findViewById(R.id.providers); 
ArrayAdapter<String> dataAdapter = new ArrayAdapter<>(this, 
      android.R.layout.simple_spinner_item, providersList); 

dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); 
checkInProviders.setAdapter(dataAdapter); 

dialog.show(); 
+1

ありがとうございます。私は最初の解決策を試してみました。 –

+0

@AlanFirblazerはお兄さんをお手伝いします – Prem

0

は、ビューを膨らませていない試してみ

ビューdialogView = inflater.inflate(R.layout.layout_checkin_items、null);底部に

AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this); 
LayoutInflater inflater = this.getLayoutInflater(); 
final View dialogView = inflater.inflate(R.layout.layout_checkin_items, null); 
dialogBuilder.setView(dialogView); 

Spinner checkInProviders = (Spinner) dialogView .findViewById(R.id.providers); 

のみ追加

AlertDialog B = dialogBu​​ilder.create()。

b.show(); 
関連する問題