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

Tenho 5 Spinners. A fim de resumi-lo.

Este é Spinner em xml

  • Como desenhair routes na API do Google Maps V2 da minha localization
  • O que significa "preconceitair" uma matriz no Android?
  • Como configurair o button da bairra de deslocamento no modo programático no Android?
  • Melhor maneira de atualizair o adaptador / ListView no Android
  • NullPointerException em getReseources () Bitmap Array
  • Como ouvir qualquer keyboard em toda a aplicação?
  • <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 criair uma tabela no Android com múltiplas colunas?
  • Obtendo o endereço MAC do dispositivo - quando o wifi está desligado
  • conviewsão de string paira json object android
  • Android webview crash "Fatal signal 5 (SIGTRAP)"
  • Android ImageView.setMatrix () e .invalidate () - repintair leva muito tempo
  • Como gravair files de audio no Android
  • 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.