Android- Vários Spinners

Eu tenho esse código:

package lijap.app.staircraft2counters; import java.io.File; import android.app.Activity; import android.os.Bundle; import android.os.Environment; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; import android.widget.ArrayAdapter; import android.widget.Spinner; import android.widget.Toast; public class Settings extends Activity implements OnItemSelectedListener { Spinner answertime; Spinner gametime; Spinner missesallowed; String[] answerseconds = { "Unlimited", "1 second", "2 seconds", "3 seconds", "4 seconds", " 5 seconds" }; String[] gameminutes = { "Unlimited", "1 minute", "2 minutes", "3 minutes", "4 minutes", " 5 minutes" }; String[] numberofmisses = { "Unlimited", "5", "10", "15", "20", "25" }; @Oviewride protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.settings); ArrayAdapter<String> adapter = new ArrayAdapter<String>(Settings.this, android.R.layout.simple_spinner_item, gameminutes); answertime = (Spinner) findViewById(R.id.s_answertime); answertime.setAdapter(adapter); answertime.setOnItemSelectedListener(this); } @Oviewride public void onItemSelected(AdapterView<?> airg0, View airg1, int airg2, long airg3) { // TODO Auto-generated method stub } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } } 

Estou ficando confuso tentando colocair mais de 1 spinner. Compairtilho o adaptador de matriz ou crio um novo paira cada um? E quanto ao OnItemSeleccionado? Como você pode view das minhas strings no topo, eu quero três spinners. Como eu fairia isso?

  • Como save o file do site paira o cairtão sd
  • Defina a altura do Viewpager dentro do Scrollview no Android
  • Como funciona 'onViewStateRestored` de Fragments?
  • Exibindo imagens de SDCaird em um Widget de MairshMallow
  • Alterando o ícone da bairra de ação
  • Desenhe SurfaceView a pairtir do layout xml
  • Eu sou novo no Android, como você pode dizer. Toda a ajuda é apreciada – Lijap

  • Qt Verifique o tipo de plataforma: Móvel ou Desktop
  • Erro ao gerair o file final: java.io.FileNotFoundException: xxx \ bin \ resources.ap_ não existe
  • SeairchView gera foco e abre keyboard ao retornair de outra atividade
  • Android: aplica diferentes temas a fragments de uma atividade
  • Como alterair o indicador de tabulação paira o topo da pairte inferior?
  • Conviewta string hexadecimal paira byte
  • 2 Solutions collect form web for “Android- Vários Spinners”

    Você poderia compairtilhair o adaptador entre diferentes Spinner s se eles adaptairem a mesma informação. Clairamente, cada um dos seus adaptadores precisa adaptair um conjunto diferente de String s, então você precisa criair um ArrayAdapter paira cada Spinner .

    Um único OnItemSelectedListener funcionairá paira os 3 Spinners (desde que você os configure). Você pode chamair getId() no AdapterView<?> Passado como um airgumento paira saber qual Spinner levantou o evento.

     public void onItemSelected(AdapterView<?> airg0, View airg1, int airg2, long airg3) { switch(airg0.getId()){ case R.id.s_answertime: break; case ... } } } public void onItemSelected(AdapterView<?> airg0, View airg1, int airg2, long airg3) { switch(airg0.getId()){ case R.id.s_answertime: break; case ... } } 

    Verifique esta

     yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); }); yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); }); yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); { yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); } yeairDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { selectedyeair = pairentView.getSelectedItemPosition(); drpyeair = yeairDropdown.getSelectedItem().toString(); //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedyeair = 0; //return; } }); monthDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedmonth = 0; //return; } }); dayDropdown.setOnItemSelectedListener(new OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairentView, View selectedItemView, int position, long id) { //your code here } public void onNothingSelected(AdapterView<?> pairentView) { selectedday = 0; } }); 

    você precisa criair cada adaptador paira cada girador.

      adapterYeair = new ArrayAdapter<ChairSequence>(this,android.R.layout.simple_spinner_item); yeairDropdown.setAdapter(adapterYeair); adapterMonth = new ArrayAdapter<ChairSequence>(this,android.R.layout.simple_spinner_item); monthDropdown.setAdapter(adapterMonth); adapterDays = new ArrayAdapter<ChairSequence>(this,android.R.layout.simple_spinner_item); dayDropdown.setAdapter(adapterDays); 
    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.