2015-11-02 137 views
1

我可以在Spinner內部使用String-array 但是我不知道是否可以放任何其他東西? 我想把一些Button放在Spinner中,但是當我把一些XML放到應用程序中時,應用程序崩潰了!可以將按鈕放在Spinner中嗎

<Spinner 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:id="@+id/spinner" 
    android:layout_below="@+id/textView" 
    android:layout_toRightOf="@+id/textView" 
    android:layout_toEndOf="@+id/textView" 
    android:layout_marginTop="125dp" > 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" /> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" /> 


</Spinner> 

這是正確的做法 或什麼?

+1

一個原因,我想到的是你沒有給按鈕..this標識是強制性... – therealprashant

+0

沒有,,,我剛纔把ID 什麼都沒有發生 – Maysara

+0

請發表您的日誌 – therealprashant

回答

0

這不會起作用,因爲這不是您將按鈕放在微調器中的方式。

由定義Spinner是一個下拉菜單,幾乎可以採取任何佈局。首先,你必須決定你的微調器排是如何。

如:

如果你想有2個按鈕,你必須做出佈局/ spinner_row.xml文件有:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" android:layout_width="match_parent" 
    android:padding="20dp" 
    android:layout_height="wrap_content"> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button" /> 

    <Button 
     android:layout_width="match_parent" 
     android:layout_weight="1" 
     android:layout_height="wrap_content" 
     android:text="New Button" 
     android:id="@+id/button2" /> 
</LinearLayout> 

,看起來像:

Result

然後,您必須製作一個適配器,以便根據您需要的數據調整微調器的每一行。

相關問題