2012-03-29 72 views
0

我在DialogFragment一個onCreateView方法,它看起來是這樣的:DialogFragment onCreateView無法顯示所有的意見

@Override 
public View onCreateView(LayoutInflater inflater, ViewGroup container, 
     Bundle savedInstanceState) { 
    View v = inflater.inflate(R.layout.purchase_dialog, container, false); 
    int title = getArguments().getInt("title"); 
    String titleString = getResources().getString(title); 
    getDialog().setTitle(titleString); 

    final TextView currentOfferPrice = (TextView) v.findViewById(R.id.current_offer_price); 
    final SeekBar editPurchasePrice = (SeekBar) v.findViewById(R.id.purchase_price); 
    editPurchasePrice 
      .setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { 

       @Override 
       public void onStopTrackingTouch(SeekBar seekBar) { 
        // TODO Auto-generated method stub 

       } 

       @Override 
       public void onStartTrackingTouch(SeekBar seekBar) { 
        // TODO Auto-generated method stub 

       } 

       @Override 
       public void onProgressChanged(SeekBar seekBar, 
         int progress, boolean fromUser) { 
        currentOfferPrice.setText("You offer $" 
          + editPurchasePrice.getProgress()); 
       } 
      }); 
    editPurchasePrice.setMax(((Purchase)getActivity()).getTotal()); 
    final DisplayHouse house = ((Purchase)getActivity()).getHouse(); 
    editPurchasePrice.setProgress(house.getMarketPrice()); 
    currentOfferPrice.setText("You offer $" 
      + editPurchasePrice.getProgress()); 
    final Button btnOffer = (Button) v.findViewById(R.id.btn_offer); 
    btnOffer.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      final DisplayHouse house = ((Purchase)getActivity()).getHouse(); 
      Log.d("log", "current market price: " + house.getMarketPrice()); 
      final int offerPrice = editPurchasePrice.getProgress(); 
      if (offerPrice >= house.getMarketPrice() * 0.999) { 
       editPurchasePrice.setProgress(offerPrice); 
       ((Purchase)getActivity()).showAcceptDialog(); 
       PortfolioManager.addHousePortfolio(house, offerPrice); 
       Log.d("log", "added a new house to portfolio."); 
      } else { 
       editPurchasePrice.setProgress(offerPrice); 
       ((Purchase)getActivity()).showRejectDialog(); 
      } 
      getDialog().dismiss(); 
     } 
    }); 

    final Button btnCancel = (Button) v 
      .findViewById(R.id.btn_purchase_dialog_cancel); 
    btnCancel.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      getDialog().dismiss(); 
     } 
    }); 

    return v; 
} 

但奇怪的是,當我打開對話框它只顯示搜索欄。我看不到TextViews和按鈕。我如何讓他們展示?

我的佈局文件是這樣的:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/purchase_dialog" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="vertical" > 

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
<SeekBar 
    android:id="@+id/purchase_price" 
    android:layout_width="200dip" 
    android:layout_height="wrap_content" 
    android:inputType="number" 
    android:gravity="center_horizontal" 
    android:layout_alignParentRight="true"> 

</SeekBar> 
<TextView 
    android:id="@+id/purchasing_text" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textColor="#FFF" 
    android:textSize="20dip" 
    android:gravity="center_horizontal" 
    android:layout_toLeftOf="@id/purchase_price" 
    android:text="@string/purchasing_text" 
    /> 
</RelativeLayout> 
<TextView 
    android:id="@+id/current_offer_price" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:textSize="20dip" 
    android:gravity="center_vertical|center_horizontal" 
/> 
<RelativeLayout 
    android:id="@+id/layout_buttons" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
<Button 
    android:id="@+id/btn_offer" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:text="@string/offer"/> 
<Button 
    android:id="@+id/btn_purchase_dialog_cancel" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_toLeftOf="@id/btn_offer" 
    android:text="@string/cancel"/> 
</RelativeLayout> 
</LinearLayout> 

回答

0

我試過你的代碼,似乎這

android:layout_height="fill_parent" 
第一的RelativeLayout的

隱藏你的其他觀點。

我試過把它改爲50dp,對話框工作正常。