2

i have a spinner and i want the spinner to prompt as select class. as we have android:hint property for edit text in android. i dont want the spinner with the dialog box. i want the spinner prompting or hinting before the seletion is made in drop down. is it possible?? please help!!!! thank you

enter image description here

i have tried the below code but dint work

classname[0] = "SELECT CLASS";

    for (int i = 1; i < classdetails.size() + 1; i++) {

        classname[i] = classdetails.get(i - 1).getClass_name() + "  "
                + classdetails.get(i - 1).getSection_name().toString();

    }

    ArrayAdapter<CharSequence> adapterClasses = new ArrayAdapter<CharSequence>(
            getApplicationContext(), R.layout.spinner_item_class,
            R.id.spinnerclasstxt, classname);
    spnrClass.setAdapter(adapterClasses);
    spnrClass.setSelection(0);

    spnrClass
            .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int pos, long arg3) {

                    int selectedindex = pos;
                    if (selectedindex == 0) {
                        spnrSubject.setVisibility(View.INVISIBLE);
                    } else {
                        spnrSubject.setVisibility(View.VISIBLE);
                        selectedClass = classdetails.get(selectedindex - 1);

                        subjectpopulate(selectedClass);
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {

                }

            });
aviz
  • 103
  • 1
  • 9

1 Answers1

1

you can set prompt for your spinner like this:

yourSpinner.setPrompt("List Options");

it also can be done through xml file.

android:prompt="@string/prompt_text"
Daniel
  • 3,322
  • 5
  • 30
  • 40