Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/190.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android微调器上添加提示_Java_Android_Spinner_Hint - Fatal编程技术网

Java 在android微调器上添加提示

Java 在android微调器上添加提示,java,android,spinner,hint,Java,Android,Spinner,Hint,我正在做一个小应用程序,我有一个旋转器。现在,当应用程序加载时,它将微调器的第一个选项显示为微调器上的文本。我希望它在加载应用程序时显示一些特殊的文本,比如提示。但当你按下微调器并设置选项时,我希望它能显示原始选项。就像现在一样,在加载应用程序时,它会显示选项号0,但我希望上面的文本显示其他字符串 这可能吗 假设现在选择了0,但在加载应用程序时,它会设置其他字符串,该字符串位于onItemSelected方法中 spinner.setOnItemSelectedListener(new OnI

我正在做一个小应用程序,我有一个旋转器。现在,当应用程序加载时,它将微调器的第一个选项显示为微调器上的文本。我希望它在加载应用程序时显示一些特殊的文本,比如提示。但当你按下微调器并设置选项时,我希望它能显示原始选项。就像现在一样,在加载应用程序时,它会显示选项号0,但我希望上面的文本显示其他字符串


这可能吗

假设现在选择了0,但在加载应用程序时,它会设置其他字符串,该字符串位于onItemSelected方法中

 spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {
                        spinner.setSelection(2);

                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                        // TODO Auto-generated method stub

                    }
                });

假设现在选择了0,但当应用程序加载它时,会设置其他字符串,该字符串位于MSelected方法中

 spinner.setOnItemSelectedListener(new OnItemSelectedListener() {

                    @Override
                    public void onItemSelected(AdapterView<?> arg0, View arg1,
                            int arg2, long arg3) {
                        spinner.setSelection(2);

                    }

                    @Override
                    public void onNothingSelected(AdapterView<?> arg0) {
                        // TODO Auto-generated method stub

                    }
                });

我用按钮而不是旋转器来处理这个问题

在项目中,我同时显示微调器和按钮,以显示它们看起来确实相同。除了按钮外,您可以将初始文本设置为任意内容

以下是该活动的外观:

package com.stevebergamini.spinnerbutton;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;

public class MainActivity extends Activity {

    Spinner spinner1;
    Button button1;
    AlertDialog ad;
    String[] countries;

    int selected = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        spinner1 = (Spinner) findViewById(R.id.spinner1);
        button1 = (Button) findViewById(R.id.button1);

        countries = getResources().getStringArray(R.array.country_names);

        //  You can also use an adapter for the allert dialog if you'd like
        //  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, countries);        

        ad = new AlertDialog.Builder(MainActivity.this).setSingleChoiceItems(countries, selected,  
                new  DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            button1.setText(countries[which]);
                            selected = which;
                            ad.dismiss();

                        }}).setTitle(R.string.select_country).create(); 


        button1.setOnClickListener( new OnClickListener(){

            @Override
            public void onClick(View v) {
                ad.getListView().setSelection(selected);
                ad.show();              
            }});

    }

}

我用按钮而不是旋转器来处理这个问题

在项目中,我同时显示微调器和按钮,以显示它们看起来确实相同。除了按钮外,您可以将初始文本设置为任意内容

以下是该活动的外观:

package com.stevebergamini.spinnerbutton;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Spinner;

public class MainActivity extends Activity {

    Spinner spinner1;
    Button button1;
    AlertDialog ad;
    String[] countries;

    int selected = -1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        spinner1 = (Spinner) findViewById(R.id.spinner1);
        button1 = (Button) findViewById(R.id.button1);

        countries = getResources().getStringArray(R.array.country_names);

        //  You can also use an adapter for the allert dialog if you'd like
        //  ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, countries);        

        ad = new AlertDialog.Builder(MainActivity.this).setSingleChoiceItems(countries, selected,  
                new  DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            button1.setText(countries[which]);
                            selected = which;
                            ad.dismiss();

                        }}).setTitle(R.string.select_country).create(); 


        button1.setOnClickListener( new OnClickListener(){

            @Override
            public void onClick(View v) {
                ad.getListView().setSelection(selected);
                ad.show();              
            }});

    }

}

很难解释你想要什么?就像上一部分写的那样;就像现在加载应用程序时,它显示选项号0,但我希望上面的文本显示其他字符串。你是在问,如何在微调器中显示字符串值而不是索引值?微调器没有android:hint属性,比如,EditText很难解释你想要什么?就像上一部分写的那样;就像现在一样,加载应用程序时它会显示选项号0,但我希望上面的文本会显示其他字符串。你是在问,如何在微调器中显示字符串值而不是索引值吗?微调器没有android:hint属性,比如EditText UnfortunitelyHMM。这实际上是可行的,但您仍然可以选择最上面的选项。有没有什么方法可以禁用微调器中的某个项目,使其无法选择?嗯,这确实可行,但您仍然可以选择最上面的选项。是否有任何方法可以禁用微调器中的项目,使其无法选择?