2013-04-27 76 views
0

這是代碼谷歌表示,用來創建自定義提醒對話(它說,創建自己的佈局,然後使用該佈局的setContentView)如何創建自定義警報diaogue

@Override 
public Dialog onCreateDialog(Bundle savedInstanceState) { 
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
// Get the layout inflater 
LayoutInflater inflater = getActivity().getLayoutInflater(); 

// Inflate and set the layout for the dialog 
// Pass null as the parent view because its going in the dialog layout 
builder.setView(inflater.inflate(R.layout.dialog_signin, null)) 
// Add action buttons 
     .setPositiveButton(R.string.signin, new DialogInterface.OnClickListener() { 
      @Override 
      public void onClick(DialogInterface dialog, int id) { 
       // sign in the user ... 
      } 
     }) 
     .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { 
      public void onClick(DialogInterface dialog, int id) { 
       LoginDialogFragment.this.getDialog().cancel(); 
      } 
     });  
return builder.create(); 
} 

谷歌則表示,以在另一個類中創建此類的實例,然後使用show()方法顯示它,但是show方法需要一個片段管理器,並且片段管理器在嘗試創建它時會收到錯誤。

這裏的說明http://developer.android.com/guide/topics/ui/dialogs.html#CustomLayout

,我需要一個微調添加到啓動一個新的活動

警報對話如果有人能想出如何得到這個工作(使對話彈出)並張貼這將是巨大

回答

1

您可以創建Alert Dialog with spinner這樣

更新

public class WvActivity extends Activity { 

TextView tx; 
String[] s = { "India ", "Arica", "India ", "Arica", "India ", "Arica", 
    "India ", "Arica", "India ", "Arica" }; 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

final ArrayAdapter<String> adp = new ArrayAdapter<String>(WvActivity.this, 
     android.R.layout.simple_spinner_item, s); 

tx= (TextView)findViewById(R.id.txt1); 
final Spinner sp = new Spinner(WvActivity.this); 
sp.setLayoutParams(new  LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT)); 
sp.setAdapter(adp); 

AlertDialog.Builder builder = new AlertDialog.Builder(WvActivity.this); 
builder.setView(sp); 
builder.create().show(); 
} 
} 
+0

我需要與微調器進行快速對話 – user2109242 2013-04-28 22:01:53