android - 为什么这两个旋转器看起来不同?

标签 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>

最佳答案

明白了。 super 简单。

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

android:spinnerMode="对话框"

其他选项是

android:spinnerMode="dropdown"

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

很简单...urg

关于android - 为什么这两个旋转器看起来不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11788554/

相关文章:

javascript - 错误: Failed to execute 'appendChild' on 'Node' : parameter 1 is not of type 'Node' while using a spinner in JavaScript

android - 带有复选框项目的微调器,这可能吗?

java - 获取 SD 卡上所有图像的数组列表

java - 操作栏选项卡的自定义位置

android - 通知设置全屏 Activity

java - Spinner Fragment 不断崩溃

java - Android 中的微调器

带有下划线 appcompat 的 Android 微调器

android - 创建 Android 应用 Release模式

android - React-Native Android Studio构建失败