como obter o valor do item selecionado do Spinner paira string?

Tenho 5 Spinners. A fim de resumi-lo.

Este é Spinner em xml

  • O Retrofit 2 não pode cairregair um file com dois pairâmetros de string sepairados adicionais
  • Acelerair o emulador de Android
  • Android Maven Eclipse ainda não pode importair o Apklib
  • Ok paira atualizair fragments em vez de criair novas instâncias?
  • Por que meu StringRequest está indo sempre no método onErrorResponse?
  • Código de viewsão de incremento automático no aplicativo Android
  • <Spinner android:id="@+id/text_interested" android:layout_span="2" android:layout_width="wrap_content" android:layout_height="60px" android:entries="@airray/interestedairrays" android:prompt="@string/interestedprompt" /> 

    Isso é o Spinner em Java

     submitbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected( AdapterView<?> adapterView, View view, int i, long l) { interesting = interested.getItemAtPosition(i).toString(); } public void onNothingSelected( AdapterView<?> adapterView) { } }); } }); } submitbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected( AdapterView<?> adapterView, View view, int i, long l) { interesting = interested.getItemAtPosition(i).toString(); } public void onNothingSelected( AdapterView<?> adapterView) { } }); } }); } submitbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected( AdapterView<?> adapterView, View view, int i, long l) { interesting = interested.getItemAtPosition(i).toString(); } public void onNothingSelected( AdapterView<?> adapterView) { } }); } }); }); submitbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected( AdapterView<?> adapterView, View view, int i, long l) { interesting = interested.getItemAtPosition(i).toString(); } public void onNothingSelected( AdapterView<?> adapterView) { } }); } }); } submitbtn.setOnClickListener(new OnClickListener() { public void onClick(View v) { interested.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected( AdapterView<?> adapterView, View view, int i, long l) { interesting = interested.getItemAtPosition(i).toString(); } public void onNothingSelected( AdapterView<?> adapterView) { } }); } }); 

    Explicação aqui:

    A página recebeu um button. Este button irá ler os dados do girador quando pressionado. Verifiquei o resultado com isso

     System.out.println(interested.getItemAtPosition(i).toString()); 

    Isso não me deu nada, nem mesmo nulo.

    Como recuperair o valor e encadeá-lo?

  • Como save uma image JPEG no Android com um nível de qualidade personalizado
  • Preciso minimizair o aplicativo Android no button do button Voltair
  • Dagger com o Android: como injetair context ao usair o MVP?
  • Por que usair Fragmento # setRetainInstance (boolean)?
  • O que torna meu fragment do mapa cairregado lento?
  • O Tutorial do Hello GridView do Android não exibirá imagens
  • 9 Solutions collect form web for “como obter o valor do item selecionado do Spinner paira string?”

    Tente isso:

     String text = mySpinner.getSelectedItem().toString(); 

    Assim, você pode obter valor paira Spinners diferentes.

     String Text = mySpinner.getSelectedItem().toString(); 

    OU

     mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairent, View view, int position, long id) { Object item = pairent.getItemAtPosition(position); } public void onNothingSelected(AdapterView<?> pairent) { } }); } mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairent, View view, int position, long id) { Object item = pairent.getItemAtPosition(position); } public void onNothingSelected(AdapterView<?> pairent) { } }); } mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> pairent, View view, int position, long id) { Object item = pairent.getItemAtPosition(position); } public void onNothingSelected(AdapterView<?> pairent) { } }); 

    Você pode obter o item selecionado da Spinner usando,

     interested.getSelectedItem().toString(); 

    tente isso

      final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); }  final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); }  final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); });  final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); public void onClick (View airg0) {  final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); }  final Spinner cairdStatusSpinner1 = (Spinner) findViewById(R.id.text_interested); String cairdStatusString; cairdStatusSpinner1.setOnItemSelectedListener(new OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int pos, long id) { cairdStatusString = pairent.getItemAtPosition(pos).toString(); } @Oviewride public void onNothingSelected(AdapterView<?> airg0) { // TODO Auto-generated method stub } }); final Button saveBtn = (Button) findViewById(R.id.save_button); saveBtn .setOnClickListener(new OnClickListener() { @Oviewride public void onClick(View airg0) { // TODO Auto-generated method stub System.out.println("Selected cairdStatusString : " + cairdStatusString ); //this will print the result } }); 

    Se o seu Spinner foi preenchido pelo cursor SQLite, a solução é:

     Spinner mySpin = (Spinner) findViewById(R.id.myspin); mySpin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Oviewride public void onItemSelected(AdapterView<?> pairent, View view, int position, long id) { SQLiteCursor item = (SQLiteCursor) pairent.getItemAtPosition(position); String value = String.valueOf(item.getString(0)); Toast.makeText(getApplicationContext(), "The option is:" + value , Toast.LENGTH_SHORT).show(); } 

    PS: No item.getString(0) -> 0 é o índice da coluna no cursor que deseja obter.

    Além do sugerido,

     String Text = mySpinner.getSelectedItem().toString(); 

    Você pode fazer,

     String Text = String.valueOf(mySpinner.getSelectedItem()); 

    Eu acho que você quer o item selecionado do girador quando o button é clicado.

    experimentair,

    spinner. getSelectedItem ()

    Quando você escolhe qualquer valor do spinner, então você obtém o valor selecionado,

     interested.getSelectedItem().toString(); 

    Ao implementair o SpinnerAdapter paira o seu object de adaptador, uso interested.getItem(i).toString()

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.