2013-04-28 74 views
8

我知道如何進行警告對話框,但我需要用微調器創建一個對話框,以便在彈出時人員可以選擇發生什麼。有沒有人有一個微調的警告對話框的代碼或知道任何好的教程?如何使用微調器進行警告對話框

在此先感謝

+6

這不是一個真正的問題嗎? – farukdgn 2015-05-16 21:39:36

回答

16
LayoutInflater li = LayoutInflater.from(context); 

View promptsView = li.inflate(R.layout.my_dialog_layout, null); 

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context); 

alertDialogBuilder.setView(promptsView); 

// set dialog message 

alertDialogBuilder.setTitle("My Dialog.."); 
alertDialogBuilder.setIcon(R.drawable.ic_launcher); 
// create alert dialog 
final AlertDialog alertDialog = alertDialogBuilder.create(); 

final Spinner mSpinner= (Spinner) promptsView 
     .findViewById(R.id.mySpinner); 
final Button mButton = (Button) promptsView 
     .findViewById(R.id.myButton); 

// reference UI elements from my_dialog_layout in similar fashion 

mSpinner.setOnItemSelectedListener(new OnSpinnerItemClicked()); 

// show it 
alertDialog.show(); 
alertDialog.setCanceledOnTouchOutside(false); 

其中

my_dialog_layout是你包含了微調mySpinner

EDIT彈出佈局:

public class OnSpinnerItemClicked implements OnItemSelectedListener { 

     @Override 
     public void onItemSelected(AdapterView<?> parent, 
       View view, int pos, long id) { 
      Toast.makeText(parent.getContext(), "Clicked : " + 
        parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show(); 


     } 

     @Override 
     public void onNothingSelected(AdapterView parent) { 
      // Do nothing. 
     } 
    } 
+0

onSpinnerItemclicked帶下劃線紅色 – user2109242 2013-04-28 22:43:44

+0

是的,先生,因爲它應該是!你需要定義它!這是你第一次與紡紗廠合作嗎? – Swayam 2013-04-28 22:47:19

+0

是的,我該如何定義它 – user2109242 2013-04-28 22:47:36