Spinner with a call icon

Asked

Viewed 220 times

0

Hello, I’m trying to make a spinner with the options: "Open Today" and "It doesn’t matter".

In my layout, I do not want anything written and a clock icon to appear, when clicked, load the spinner list.

I put the image in the background of the spinner.

It turns out that it expands as selected the option from the list, will have to leave it of fixed size?

And also the other question is that the list with the options can be added only at position 1, because as I do not know this, I am adding the first element of the list as "" so that in the layout is only the image.

I tried to put as listheader, but it didn’t work. Thank you very much! What I am using:

No Layout:
 <Spinner
android:id="@+id/spinner3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center_horizontal"
android:scrollIndicators="end"
android:textAlignment="center"
android:background="@drawable/local" />

No código:
horario = new ArrayList<>();
horario.add("");
horario.add("Aberto Hoje");
horario.add("Não importa");
adapter = new ArrayAdapter<String>(getApplication(), android.R.layout.simple_spinner_dropdown_item, horario);
    spinnerhora.setAdapter(adapter);
  • You can put an imageview underneath the spinner. Before the user clicks the spinner, make it invisible.

  • Hi Tiago, it’s a good idea, but how do I (in code) so that when the user click on Imageview open the spinner?

1 answer

0

In Layout

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/image3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/imagem"/>
    <Spinner
        android:id="@+id/spinner3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center_horizontal"
        android:scrollIndicators="end"
        android:textAlignment="center"
        android:background="@drawable/local"
        android:visibility="gone" />
</RelativeLayout>

In the code

Spinner spinner3 = (Spinner) findViewById(R.id.spinner3);
ImageView image3 = (ImageView) findViewById(R.id.image3);

ArrayList horario = new ArrayList<>();    
horario.add("Aberto Hoje");
horario.add("Não importa");
ArrayAdapter adapter = new ArrayAdapter<String>(getApplication(), android.R.layout.simple_spinner_dropdown_item, horario);
spinner3.setAdapter(adapter);

image3.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
        spinner3.setVisibility(View.VISIBLE);
    }
});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.