0
I am developing a form where I want to add the spinner, but when I add it in the xml file, nothing appears on the screen, only the box marked as you can see below:
I already added my spinner options in STRINGS. Here’s my xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:background="@android:color/background_light">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/nome1"
android:textColorHint="#9b9a9a"
android:hint="*Nome:"
android:textSize="14dp"
android:textColorLink="#050000"
android:backgroundTint="#020000"
android:textColor="#050000"
android:layout_above="@+id/email"
android:layout_alignLeft="@+id/msg"
android:layout_alignRight="@+id/msg"
android:layout_alignEnd="@+id/msg" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#9b9a9a"
android:inputType="textPostalAddress"
android:ems="10"
android:id="@+id/email"
android:hint="*E-mail:"
android:textSize="14dp"
android:textColorLink="#050000"
android:backgroundTint="#020000"
android:textColor="#050000"
android:layout_above="@+id/msg"
android:layout_alignLeft="@+id/msg"
android:layout_alignStart="@+id/msg"
android:layout_marginBottom="36dp"
android:layout_alignRight="@+id/msg"
android:layout_alignEnd="@+id/msg" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#9b9a9a"
android:inputType="phone"
android:ems="10"
android:id="@+id/telefone"
android:hint="Telefone:"
android:textSize="14dp"
android:textColorLink="#050000"
android:backgroundTint="#020000"
android:textColor="#050000"
android:layout_above="@+id/nome1"
android:layout_alignLeft="@+id/msg"
android:layout_alignRight="@+id/msg"
android:layout_alignEnd="@+id/msg" />
<Button
android:layout_width="85dp"
android:layout_height="40dp"
android:text="Enviar"
android:id="@+id/send"
android:layout_above="@+id/textView8"
android:layout_alignRight="@+id/textView8"
android:layout_alignEnd="@+id/textView8" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="#9b9a9a"
android:inputType="textPersonName"
android:ems="10"
android:id="@+id/endereco"
android:hint="Endereço:"
android:textSize="14dp"
android:textColorLink="#050000"
android:backgroundTint="#020000"
android:textColor="#050000"
android:layout_above="@+id/telefone"
android:layout_alignLeft="@+id/msg"
android:layout_alignRight="@+id/msg"
android:layout_alignEnd="@+id/msg" />
<EditText
android:layout_width="wrap_content"
android:layout_height="120dp"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="5"
android:ems="10"
android:id="@+id/msg"
android:hint="*Mensagem"
android:textSize="14dp"
android:textColorHint="#9b9a9a"
android:layout_above="@+id/send"
android:layout_alignRight="@+id/send"
android:layout_alignEnd="@+id/send"
android:layout_alignLeft="@+id/textView8"
android:layout_alignStart="@+id/textView8"
android:backgroundTint="#020000"
android:textColor="#050000"
android:textColorLink="#050000" />
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/spinner"
android:layout_below="@+id/imageView"
android:layout_alignLeft="@+id/endereco"
android:layout_alignStart="@+id/endereco"
android:clickable="false"
android:spinnerMode="dropdown" />
</RelativeLayout>
And here is my class where it is called the form Intent:
public class Reclame extends Cronograma implements AdapterView.OnItemSelectedListener{
Spinner opcoes;
Button btnSend;
EditText Nome;
String Subject;
EditText Message;
EditText Endereco;
EditText Telefone;
EditText Email;
@Override
public View onCreateView(LayoutInflater inflater,
ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.reclame, container, false);
Nome = (EditText) view.findViewById(R.id.nome1);
Subject = "Reclamação";
Message = (EditText) view.findViewById(R.id.msg);
Endereco = (EditText) view.findViewById(R.id.endereco);
Telefone = (EditText) view.findViewById(R.id.telefone);
Email = (EditText) view.findViewById(R.id.email);
btnSend = (Button) view.findViewById(R.id.send);
opcoes = (Spinner)view.findViewById(R.id.spinner);
opcoes.setOnItemSelectedListener(this);
btnSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
ArrayAdapter adapter = ArrayAdapter.createFromResource(v.getContext(), R.array.option, android.R.layout.simple_spinner_item);
opcoes.setAdapter(adapter);
String nome = Nome.getText().toString();
String message = Message.getText().toString();
String matricula = Endereco.getText().toString();
String telefone = Telefone.getText().toString();
String ema = Email.getText().toString();
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"meu_email"});
email.putExtra(Intent.EXTRA_SUBJECT, Subject);
email.putExtra(Intent.EXTRA_TEXT, "Nome: " +nome +'\n'+ "Endereço: "+matricula + '\n'+ "Telefone: "+telefone + '\n'+ "E-mail: "+ema + '\n'+ '\n'+message);
email.setType("message/rfc822");
startActivity(Intent.createChooser(email, "Selecione o serviço de e-mail:"));
}
});
return view;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
TextView mtext = (TextView) view;
//Toast.makeText(this, "Você selecionou: "+mtext.getText(), Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
What am I doing wrong, that does not appear the spinner?
I did what you suggested and showed up, only the spinner still doesn’t show up. what I find strange is that when I add it in xml it does not show the ITEM 1 box, it just shows the box as you see in the first image.
– Carlos Diego
The array
option
has elements?– ramaral
ramaral I managed to solve the problem, it is adding the spinner in the form, the pro is that the invisible spinner ta, I only found pq when it leaves by clicking on the screen moved down the options of the spinner, but when I choose an option it turns invisible again
– Carlos Diego
In the spinner has
android:layout_below="@+id/imageView"
I don’t see any imageView– ramaral
I removed that line.. and changed my theme and already appeared the options, but when I choose the option, it disappears again.
– Carlos Diego