标签: android-spinner

在android中动态设置微调器的位置?

我正在开发一个应用程序,我需要根据以前的屏幕值动态设置微调器值.我的代码......

Main.java.

String[] values = {"All","Only Walk-in","Only Phone","Only Web","Walkin-phone","Walkin-web","phone-web"};

 /*ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item,apttypes);
    spinner.setAdapter(adapter);*/
Run Code Online (Sandbox Code Playgroud)

但在这里我想要的是从前一个屏幕我得到一些价值(像旋转器位置).基于我需要设置微调器值来显示...

如果我得到值= 0意味着,从前一个屏幕意味着,

我需要设置微调器值以从顶部的数值数组中显示"全部".

如果我得到值= 5的意思,

我想设置微调器值显示为"Walkin-web"

我怎样才能做到这一点.谁能帮我这个...

android spinner android-spinner

1
推荐指数
1
解决办法
1万
查看次数

在Android 2.2上的ActionBarSherlock中用作自定义视图时的Spinner下拉样式

我正在使用ActionBarSherlock.在我的应用程序中,我需要2个旋转器在操作栏中,所以我使用列表导航+添加第二个微调器与自定义视图.

我使用以下代码将微调器添加到自定义视图:

ActionBar bar = getSupportActionBar();

// FALLBACK: Use native actionbar dropdown style for 11+ API. Or use ActionBarSherlock style.
int dropDownStyle = (VERSION.SDK_INT < 11) ? R.attr.actionDropDownStyle : android.R.attr.actionDropDownStyle;           

MyAdapter someAdapter = new MyAdapter(this, list);          

Spinner mySpinner = new Spinner(this, null, dropDownStyle);                    
mySpinner.setAdapter(someAdapter);        
mySpinner.setOnItemSelectedListener(this);

bar.setCustomView(mySpinner);
bar.setDisplayShowCustomEnabled(true);
Run Code Online (Sandbox Code Playgroud)

在Android 4.0.3上一切都很完美.

Android 2.2行为:

列表导航微调器在Android 4.0.4上看起来像(下拉列表).但是自定义视图中的微调器显示对话框而不是微调器视图单击下拉菜单.

所以我需要在Android 2.2上的自定义视图中显示Spinner,就像Android 4.0.4上的下拉菜单一样.

在此输入图像描述

android android-spinner actionbarsherlock android-actionbar

1
推荐指数
1
解决办法
4791
查看次数

如何在同一个Activity中单击实现具有不同项目列表和不同操作的多个微调器

我想在Android中实现两个不同的微调器,微调器有不同的数据集

这是随着年龄的旋转器,其使用定义的字符串数组的所有年龄范围(ES 18-20,19-21等)

 <Spinner
        android:id="@+id/spAge"
        android:layout_width="match_parent"
        android:layout_height="35dp"
        android:entries="@array/age_array" 
        tools:listitem="@android:layout/simple_spinner_item/>
Run Code Online (Sandbox Code Playgroud)

这是性爱的旋转器,只显示男性女性两个项目

 <Spinner
       android:id="@+id/spSex"
       android:layout_width="match_parent"
       android:layout_height="35dp"
       android:entries="@array/sex_array"
       tools:listitem="@android:layout/simple_spinner_item />
Run Code Online (Sandbox Code Playgroud)

对于每个选定的项目,我的活动应将关联的所选项目值设置为两个对象:

String selectedAge;
String selectedItem;
Run Code Online (Sandbox Code Playgroud)

我看到的样本不包含多个微调器,其中设置了不同的项目,并且对所选项目的操作不同,我不知道如何解决问题.

android android-layout android-spinner

1
推荐指数
1
解决办法
2万
查看次数

旋转模式不起作用

我有两个旋转器,一个带

android:spinnerMode="dialog"
Run Code Online (Sandbox Code Playgroud)

和另一个

android:spinnerMode="dropdown"
Run Code Online (Sandbox Code Playgroud)

现在,当我点击任一个微调器时,我发现它们之间没有区别.

android android-widget android-spinner

1
推荐指数
1
解决办法
2747
查看次数

Android:spinner setSelection不起作用

我无法使用我的微调器setSelection()方法解决问题.我正在编写一个程序来保存数据,我从数据库中的某种表中获取数据.当用户打开程序时,它从数据库加载数据并添加3个空"表"行,以便用户可以填充并保存.当加载来自数据库的数据时,我需要正确设置微调器的选择,但是当我尝试我的代码时,它只是不起作用,并且屏幕上的所有微调器都会出现,并且选择了0项.这是我的代码.
OnCreate()方法:

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.data);

    dbHelper = new DBHelper(this);
    content = (LinearLayout) findViewById(R.id.content);
    inflater = getLayoutInflater();

    Calendar c = Calendar.getInstance(); 
    cur_year = c.get(Calendar.YEAR);
    cur_month = c.get(Calendar.MONTH);
    cur_day = c.get(Calendar.DAY_OF_MONTH);

    load_array();
    load_database();

    for (int i = 0; i < EMPTY_LINES_TO_DRAW; i++) {
        draw();
    }
}
Run Code Online (Sandbox Code Playgroud)

load_array()是一个加载数组"供应商"(来自文件)的函数,然后我将它放入我的微调器适配器中.
load_database()函数:

private void load_database() {
    SQLiteDatabase db = dbHelper.getWritableDatabase();
    Cursor c = db.query("mytable", null, null, null, null, null, null);

    if (c.moveToFirst()) {

        int date_1_Index = c.getColumnIndex("date_1");
        int key_Index = c.getColumnIndex("key_field"); …
Run Code Online (Sandbox Code Playgroud)

android spinner android-spinner

1
推荐指数
1
解决办法
9170
查看次数

在Android 5.0中向菜单栏添加微调/下拉菜单

我需要在我的Android应用程序的顶部菜单栏中添加一个微调器,如下所示:

在此输入图像描述

在Android 5.0之前,我只是使用:

final android.app.ActionBar actionBar = getActionBar();
actionBar.setDisplayShowTitleEnabled(false); // DEPRACATED
actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST)
Run Code Online (Sandbox Code Playgroud)

但该方法已被弃用.我已经浏览了所有示例:http://developer.android.com/samples/ui.html但是没有一个人有一个微调/下拉菜单来基于我的代码.

鉴于不推荐使用NAVIGATION_MODE_LIST,如何添加与Android 5.0兼容的微调器以及所有以前的版本?

更新:在我的代码中可以看到添加工具栏后,发生错误,因为它注意到即使它无法看到导入android.support.v7.widget.Toolbar; 清楚列出

在此输入图像描述

android android-spinner drop-down-menu

1
推荐指数
1
解决办法
9414
查看次数

Android更改微调器主题/样式与底部边框

我将数据加载到其后有一个微调器.风格不如我所料.

微调器代码

<Spinner
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:id="@+id/spinnerGender"
                android:spinnerMode="dropdown"
                android:layout_marginLeft="-5dp"
                android:layout_marginTop="5dp"/>
Run Code Online (Sandbox Code Playgroud)

目前的风格. 在此输入图像描述

我的预料 在此输入图像描述

如何更改微调器的主题/样式

android spinner android-theme android-spinner

1
推荐指数
1
解决办法
8249
查看次数

如何更改Spinner下拉项目的文本颜色?

我想将Spinner下拉项目的文本颜色更改为黑色.

我有一个自定义Spinner,列出了不同的语言.它有一个ImageView和一个TextView.微调器显示在带有白色文本的蓝色背景上,看起来很好.

问题是当它被点击时,下拉显示但文本几乎看不到,因为下拉的浅灰色和文本的白色.

这是Spinner的代码activity_main.xml:

<Spinner
    android:id="@+id/languageSpinner"
    style="@android:style/Widget.Material.Light.DropDownItem.Spinner"
    android:layout_width="140dp"
    android:layout_height="40dp"
    android:prompt="@string/selectLanguageSpinner"
    android:spinnerMode="dropdown" />
Run Code Online (Sandbox Code Playgroud)

这是spinner_row_layout.xml:

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="8dp"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical" />

        <TextView
            android:id="@+id/language"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_gravity="center_vertical"
            android:layout_marginEnd="10dp"
            android:layout_marginStart="5dp"
            android:gravity="center_vertical"
            android:lineSpacingExtra="20dp"
            android:minHeight="40dp"
            android:textColor="@color/white"
            android:textSize="20sp" />
    </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这里文本颜色设置为白色,因为当没有选择任何内容时我需要它是白色的.

这是以下代码styles.xml:

<!-- Base application theme. -->
    <style name="AppTheme" parent="Base.Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/myAppPrimaryColor</item>
        <item name="colorPrimaryDark">@color/myAppPrimaryDarkColor</item>
        <item name="colorAccent">@color/myAppAccentColor</item>
        <item …
Run Code Online (Sandbox Code Playgroud)

android spinner android-spinner

1
推荐指数
1
解决办法
5585
查看次数

如何在MultiSelection Spinner Android中超出限制时禁用项目选择

我试图取消选择一旦限制超过.在下面给出的代码中,当最大选择限制超过时,我能够实现吐司.但是当我试图在限制超过时禁用或取消选择项目时,它不起作用.

public class MultiSelectionSpinner1 extends Spinner implements
        OnMultiChoiceClickListener {

    public interface OnMultipleItemsSelectedListener{
        void selectedIndices(List<Integer> indices);
        void selectedStrings(List<String> strings);
    }
    private OnMultipleItemsSelectedListener listener;

    String[] _items = null;
    boolean[] mSelection = null;
    boolean[] mSelectionAtStart = null;
    String _itemsAtStart = null;

    ArrayAdapter<String> simple_adapter;

    public MultiSelectionSpinner1(Context context) {
        super(context);
        simple_adapter = new ArrayAdapter<>(context,
                android.R.layout.simple_spinner_item);
        super.setAdapter(simple_adapter);
    }

    public MultiSelectionSpinner1(Context context, AttributeSet attrs) {
        super(context, attrs);

        simple_adapter = new ArrayAdapter<>(context,
                android.R.layout.simple_spinner_item);
        super.setAdapter(simple_adapter);
    }

    public void setListener(OnMultipleItemsSelectedListener listener){
        this.listener = listener;
    }

    public void onClick(DialogInterface dialog, int …
Run Code Online (Sandbox Code Playgroud)

android multipleselection android-spinner android-checkbox

1
推荐指数
1
解决办法
570
查看次数

微调器宽度与微调器项目宽度不匹配

当我使用特定的宽度400dp作为DropDown项目的宽度时,spinner它正确匹配。

但是,当我match_parent用于spinnercustom_spinner_item宽度时,它不匹配吗?图片可能会给您一个想法在此处输入图片说明 我的代码有什么问题?我想要使​​用相同的宽度match_parent吗?

这是我的习惯 custom_spinner_item

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView
        android:id="@+id/textView"
        android:layout_width="400dp"            // width
        android:layout_height="30dp"
        android:textSize="18dp"
        android:text="wallets"
        android:layout_marginLeft="5dp"
        android:paddingLeft="5dp"
        android:background="#FFFFFF"
        android:textColor="#282727"/>
    <View
        android:layout_width="400dp"
        android:layout_height="1dp"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="5dp"
        android:background="#8e8c8c"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

我的片段

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/appbackground"
    android:paddingRight="5dp"
    android:paddingLeft="5dp"
    android:paddingTop="5dp">   

    // some code

   <LinearLayout
        android:id="@+id/dropDownLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@drawable/zxing_roundedbgwhite"
        android:orientation="vertical">
        <Spinner
            android:id="@+id/spinner1"
            android:layout_width="400dp"        // width
            android:layout_height="35dp"
            android:dropDownWidth="400dp"       // width
            android:spinnerMode="dropdown" />
    </LinearLayout>

    // …
Run Code Online (Sandbox Code Playgroud)

android spinner android-spinner

1
推荐指数
1
解决办法
1413
查看次数