2012-08-03 73 views
2

試圖讓彈出一個新的小屏幕的微調,用戶可以選擇他們的選擇,而不僅僅是一個下拉菜單。我一直在尋找,所有「基本」微調器的例子似乎都能完成彈出式微調器,但是在我的生活中,我無法在我的機器上完成它。爲什麼這兩個紡紗廠看起來不一樣?

我有什麼:http://developer.android.com/guide/topics/ui/controls/spinner.html

我想要什麼:http://www.mkyong.com/android/android-spinner-drop-down-list-example/

我會發布的實際圖片,但我沒有信譽分這麼做......

//@SuppressLint("ParserError") 
public class Timer_appActivity extends Activity implements OnClickListener { 
private static final String TAG = "TimerActivity"; 
//find view and assign to Java variable 
EditText Hr; 
EditText Min; 
EditText Sec; 
Button buttonGo; 
Button buttonReset; 
Spinner mySpinner; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main2); 

    //find views 
    mySpinner = (Spinner) findViewById(R.id.playlistSpinner); 

    //get the names of the playlists on device 
    List<String> list = new ArrayList<String>(); 
    String[] proj = {MediaStore.Audio.Playlists.NAME}; 
    Cursor myCursor = getContentResolver().query(Uri.parse("content://com.google.android.music.MusicContent/playlists"), proj, null, null, null); 
    if (myCursor.getCount() > 0) { 
     myCursor.moveToFirst(); 
     do { 
      list.add(myCursor.getString(0)); 
     } while (myCursor.moveToNext()); 
    } 
    myCursor.close(); 
    //define spinner adapter with nice spacing and playlist names 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.row, R.id.playlistNames, list); 
    //populate adapter with playlist names 
    mySpinner.setAdapter(adapter); 

    //add listener to buttons 
    //buttonGo.setOnClickListener(this); 
    //buttonReset.setOnClickListener(this); 

} 
} 

和row.xml樣子:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id = "@+id/linearlayout1" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:orientation="vertical" 
> 
<TextView 
android:id="@+id/playlistNames" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:textSize = "25dp" 
android:paddingLeft="5dp" 
android:paddingTop="5dp" 
android:paddingRight="5dp" 
android:paddingBottom="5dp" 
/> 
</LinearLayout> 

和MAIN2的XML看起來像:(對微調的比特是最後進入)

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

<TableRow 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="15dp" 
    android:layout_marginTop="30dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 

    <TextView 
     android:id = "@+id/HoursLabel" 
     android:text = "@string/stringHours" 
     android:layout_column = "1" 
     android:textSize="30dp" 
     android:gravity = "center" 
    /> 
    <TextView 
     android:id = "@+id/MinLabel" 
     android:text = "@string/stringMin" 
     android:layout_column = "3" 
     android:textSize="30dp" 
     android:gravity = "center" 
    /> 
    <TextView 
     android:id = "@+id/SecLabel" 
     android:text = "@string/stringSec" 
     android:layout_column = "5" 
     android:textSize="30dp" 
     android:gravity = "center" 
    /> 
    <TextView 
     android:layout_width="15dp" 
    /> 
</TableRow> 

<TableRow 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="15dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:id ="@+id/HoursNum" 
     android:hint = "@string/NoNumHrs" 
     android:gravity = "center_horizontal" 
     android:textSize="50dp" 
     android:inputType="numberDecimal" 
     android:layout_column = "1" 
    /> 
    <TextView 
     android:id = "@+id/colon1" 
     android:text = "@string/colon" 
     android:textSize = "50dp" 
    /> 
    <EditText 
     android:id ="@+id/MinNum" 
     android:hint = "@string/NoNumMin" 
     android:textSize="50dp" 
     android:inputType="numberDecimal" 
     android:gravity = "center_horizontal" 
    /> 
    <TextView 
     android:id = "@+id/colon2" 
     android:text = "@string/colon" 
     android:textSize = "50dp" 
    /> 
    <EditText 
     android:id ="@+id/SecNum" 
     android:hint = "@string/NoNumSec" 
     android:textSize="50dp" 
     android:inputType="numberDecimal" 
     android:gravity = "center_horizontal" 
    /> 
</TableRow> 
<TableRow 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="15dp" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <Spinner 
    android:id="@+id/playlistSpinner" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:prompt="@string/selectplaylist" 
    android:layout_marginTop="25dp" 
    android:layout_column = "3"/> 
</TableRow> 

+1

你需要[選擇基於平臺版本主題(http://developer.android.com/guide/topics/ui/themes.html#SelectATheme) ?這是[關於這個問題的早期問題](http://stackoverflow.com/questions/9681648/how-to-use-holo-light-theme-and-fall-back-to-light-on-pre-honeycomb-設備)。 – 2012-08-03 03:46:50

+1

@Ken,感謝您的提示......它肯定與選擇的主題有關。我在我的Manifest文件中做了一個快速的改變,而其餘部分現在看起來很糟糕,這個微調按照我想要的那樣工作。我會做一些閱讀如何定製主題......我認爲soln就在那裏。謝謝!對於那些掙扎...進入AndroidManifest.xml並在之後添加以下內容:android:theme =「@ android:style/Theme.Dialog」。應該做的伎倆。 – scottndecker 2012-08-04 01:03:47

回答

4

明白了。超級簡單。

將以下內容添加到xml文件中微調器的屬性列表中。

機器人:spinnerMode = 「對話框」

另一種選擇是

機器人:spinnerMode = 「下拉菜單」

這適用於11級以上,我相信......(也許更低? )

那麼容易... URG