0

How to set the string values on spinner prompt?

The process how I am doing is:

I am able to retrieve the json data(it has only one single value), so I am getting the single text with the help of String.

Later, I am trying to set the string value in Spinner prompt

SP_gender is called as Spinner here. In String gender1, I have texts called as "male"

 String gender1 = i.getStringExtra("bundle_CusGender");
 SP_gender.setPrompt(gender1);
 System.out.println("Check bundle_CusGender = : " + gender1);

When I try to print this, I am getting a value as male

System.out: Check bundle_CusGender = : male

How should I set the single text in spinner Android?

halfer
  • 19,824
  • 17
  • 99
  • 186
Achiever
  • 1,626
  • 10
  • 30
  • 54

1 Answers1

0

Firstly the setPrompt() methods documentation states:

Sets the prompt to display when the dialog is shown.

Which is pretty vague but internally it calls the setPromptText() method which sets the description on the popup and has the following documentation.

Set hint text to be displayed to the user. This should provide a description of the choice being made.

So if I am understanding your question correctly you want to set the spinners selected item. You should be using either setSelection(int) or setSelection(int, boolean)

For those to work you would need to give your spinner an adapter if you haven't already. If you don't know how you should check out this answer which explains in more detail.

string.Empty
  • 10,393
  • 4
  • 39
  • 67