2

I get a part the text of spinner on selection using the code bellow

Toast.makeText(MainActivity.this, adapter.getItem(position).substring(0,adapter
                .getItem(position).lastIndexOf("-")), Toast.LENGTH_LONG).show();

When I select the spinner, I get text like

001-00434016881

Now I want to replace this text (001-00434016881) on

001-00434016881 - MAruf Parvez Khan

My spinner image like this....

enter image description here

I got some solution from my previous question . But this my new problem.

Thanks in advance ...

Enamul Haque
  • 4,789
  • 1
  • 37
  • 50
  • 1
    And what do you display now with the current code. If you provide some more code (of your spinner, adapter, etc), it will be easier for us to help you. – Vesko Apr 18 '15 at 18:08

1 Answers1

1

You can try this

String[] temp= yourSpinner.getSelectedItem().toString().split("-");

Toast.makeText(MainActivity.this, temp[0]+"-"+temp[1], Toast.LENGTH_SHORT).show();

Or if you want to show your toast when user select item from Spinner you can try this

@Override
public void onItemSelected(AdapterView<?> parent, View view,int pos, long arg3) 
{
    String[] temp= parent.getItemAtPosition(pos).toString().split("-");
    Toast.makeText(context, temp[0]+"-"+temp[1], Toast.LENGTH_SHORT).show();
}
Melquiades
  • 8,496
  • 1
  • 31
  • 46
A.R.
  • 2,631
  • 1
  • 19
  • 22