当来自微调阵列的android没有选择我显示的默认值 [英] display default value when i nothing selected from spinner array android

查看:93
本文介绍了当来自微调阵列的android没有选择我显示的默认值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一个微调使用数组,现在,即使微调它会自动从微调数组第一个值,我想没事的时候由用户选择的形式微调阵列设置默认值我没有选择任何值将值微调,意味着我得到我设定,当我不选择任何值默认值,这是可能的,什么是利用onNothingSelected(适配器视图的....低于code,当用户选择手动微​​调的任何值应该运行,但它始终运行并获得第一个值是数组,所以请告诉当来自微调选择我没有如何得到默认值,我可以没有任何选择的方法使用..?

  ArrayAdapter<串GT; CurrencyAdapter =新ArrayAdapter<串GT;(这一点,
    android.R.layout.simple_dropdown_item_1line,外币);
currency.setAdapter(CurrencyAdapter);
currency.setOnItemSelectedListener(新AdapterView.OnItemSelectedListener()
{
    @覆盖
    公共无效onItemSelected(适配器视图<>母公司,观景,INT位置,长的ID)
    {
    }    @覆盖
    公共无效onNothingSelected(适配器视图<>母公司)
    {
    }
});


解决方案

一个相关的问题我问了前两天可以帮助你在这里,看看<一个href=\"http://stackoverflow.com/questions/7975394/how-to-use-android-spinner-like-a-drop-down-list\">How使用Android微调就像一个下拉列表,看到一些我发现有用的答案。

和没有, onNothingSelected()不做你以后......你想看看这些方法 setSelection( ) setSelectionInt()中的问题,我提到的。

i make a spinner put the value in spinner using array,now even i was not select any value from spinner it automatically takes first value from spinner array, i want to set default value when nothing is selected form spinner array by user,means i get default value which i set ,when i was not selected any value, is this possible, and what is the use of onNothingSelected(AdapterView ....below code should run when user select manually any value from spinner but it run always and get first value which is in array,so pls tell how to get default value when i nothing selected from spinner, can i use on nothing selected method..?

ArrayAdapter<String> CurrencyAdapter = new ArrayAdapter<String>(this, 
    android.R.layout.simple_dropdown_item_1line, Currency);
currency.setAdapter(CurrencyAdapter);
currency.setOnItemSelectedListener( new AdapterView.OnItemSelectedListener()
{
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) 
    {
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent)
    {
    }
});

解决方案

A related question I asked a couple of days ago could help you here, have a look at How to use Android Spinner like a drop-down list and see some of the answers which I found helpful.

And no, onNothingSelected() does not do what you're after... you want to have a look at the methods setSelection() and setSelectionInt() in the question I referred to.

这篇关于当来自微调阵列的android没有选择我显示的默认值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆