为什么这两个微调器看起来不一样?

时间:2012-08-03 02:46:51

标签: android spinner

尝试制作一个弹出一个新的小屏幕的微调器,用户可以从中选择,而不仅仅是下拉菜单。我一直在寻找,所有“基本”的旋转器示例似乎都完成了弹出式旋转器,但对于我的生活,我无法在我的机器上完成它。

我有什么: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 个答案:

答案 0 :(得分:4)

知道了。超级简单。

将以下内容添加到xml文件中微调器的属性列表中。

机器人:spinnerMode = “对话框”

其他选项是

机器人:spinnerMode = “下拉菜单”

这适用于11级及以上,我相信......(也许更低?)

这么容易......伙计