2012-07-17 22 views

回答

1

是可能的。您需要設計您的custom layout並在彈出窗口中調用該佈局

假設這是我的pop up代碼。

private void showPopUp() 
{ 
    final AlertDialog.Builder helpBuilder = new AlertDialog.Builder(this); 
    helpBuilder.setTitle(""); 

    LayoutInflater inflater = getLayoutInflater(); 
    final View PopupLayout = inflater.inflate(R.layout.jobselection, null); 
    helpBuilder.setView(PopupLayout); 

    final AlertDialog helpDialog = helpBuilder.create(); 
    helpDialog.show(); 

    spn = (Spinner)PopupLayout.findViewById(R.id.spn); 
    caneclbtn = (ImageButton)PopupLayout.findViewById(R.id.cancelBtn); 
    selectallbtn = (ImageButton)PopupLayout.findViewById(R.id.selectBtn); 
    clearallbtn  = (ImageButton)PopupLayout.findViewById(R.id.clearallBtn); 
    jobentries  = (Button)PopupLayout.findViewById(R.id.entries); 

    jobList   = (ListView)PopupLayout.findViewById(R.id.list); 

    //ur code here. You can add your spineer with items. 
} 

在這個模塊中,你可以寫出你需要的東西。祝你好運

+0

和彈出窗口上的微調?怎麼樣? – 2012-07-17 09:38:32

+0

感謝您的回答。這工作正常,但對話框的大小是有限的。是否可以改變對話框的大小? – 2012-07-17 10:37:09

+0

在android中有一個工具,我們可以將任何頁面顯示爲對話框。所以首先創建頁面並在清單中爲該活動添加android:theme =「@ android:style/Theme.Dialog」。然後它會變大。 – 2012-07-17 10:39:36

2

如果你想在彈出窗口中顯示微調,你必須爲微調器設置android:spinnerMode =「dialog」..是的,你必須爲彈出窗口創建一個custum佈局並使其膨脹。

這裏是我的代碼:

LayoutInflater layoutInflater = (LayoutInflater)IOStatusActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE)  
final View popupView = layoutInflater.inflate(R.layout.popupai, null); 

final PopupWindow popupWindowDi = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); 

final TextView txtReadVal = (TextView)popupView.findViewById(R.id.lblPopUpAiReadFrmPLC); 
final EditText txtExpVal = (EditText)popupView.findViewById(R.id.txtPopUpAiExpVal); 
Button btnDismiss = (Button)popupView.findViewById(R.id.btnPopUpAiCancle);       
btnDismiss.setOnClickListener(new Button.OnClickListener(){ 
@Override 
public void onClick(View v) { 
popupWindowDi.dismiss(); 
}});` 

您可以添加烏爾微調爲我添加的按鈕和編輯文本。希望它有幫助。

+0

這裏是膨脹彈出式佈局的示例代碼:LayoutInflater layoutInflater =(LayoutInflater)IOStatusActivity.this.getSystemService(LAYOUT_INFLATER_SERVICE); \t \t \t \t \t final查看popupView = layoutInflater.inflate(R.layout.popupai,null); \t \t \t \t \t final PopupWindow popupWindowDi = new PopupWindow(popupView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT); – 2012-07-17 09:42:22

+0

此處popupai是您可以在xml上創建的彈出窗口的佈局。 IOStatusActivity是您想要顯示彈出窗口的活動的名稱。 – 2012-07-17 09:44:30

+0

感謝您的回答,微調控制器可以在彈出窗口中使用android:spinnerMode =「dialog」正常工作。我如何顯示自動完成的TextView? – 2012-07-17 09:51:43

0

更好地使用對話框(android.app.Dialog)來實現AutoCompleteTextView。在我看來,在PopupWindow中添加AutoCompleteTextView是不可能的(你會得到一個例外)。您可以在PopupWindow中添加Spinner。如果您使用對話框而不是彈出窗口,則可以實現兩者。

相關問題