3
I have a Spinner, where the user should select his gender: So far everything works well, but I need to leave a hint written the word sex in the spinner component, as well as in the image below:
Code I have so far:
<Spinner
android:id="@+id/spinner_sex"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/edittext_email"
android:layout_marginTop="6dp"
android:layout_marginLeft="23dp"
android:layout_marginRight="23dp"
android:entries="@array/spinner_genre_items"
android:textColor="@color/h_gray"
android:textColorHint="@color/h_gray"
android:textSize="@dimen/h_three"
android:fontFamily="sans-serif-medium">
</Spinner>
Array with Spinner items:
<string-array name="spinner_genre_items">
<item>Masculino</item>
<item>Feminino</item>
</string-array>
Java:
private Spinner mSpinnerGender;
mSpinnerGender = (Spinner) findViewById(R.id.spinner_sex);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
R.array.spinner_genre_items,
android.R.layout.simple_spinner_dropdown_item);
adapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
mSpinnerGender.setAdapter(adapter);
How could I do that?
Are you wearing a
ArrayAdapter
or a class inheritingBaseAdapter
?– rsicarelli
Actually I was not using any of the 2. Now I am using an Arrayadapter, I updated the code in the question.
– antunesleo_
Pass 3 values to your Adapter: Male, Female and Sex; Set the starting value is the position(spinner) as being 3(sex). on getCount say that your Adapter is size 2(male, female);
– Caique Oliveira
In this case I would not use the array-list to popular Spinner but Arrayadapter?
– antunesleo_