I’m new to this forum, but i came here because i need some help with some spinners i’m trying to create for an Android app.
I have created 1 spinner and that works fine, but now i want to add a second spinner and i want the if statement i have to work depending on the two selections of the spinners.
For example, if item 1 is selected on spinner 1 and item 3 is selected on spinner 2 then do the if statement.
But i don’t know how to get that to work. could anyone help me please.
This is the code i have now for 1 spinner:
Spinner spinner = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
this, R.array.weight_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
public class MyOnItemSelectedListener implements OnItemSelectedListener
{
public void onItemSelected(AdapterView<?> parent,
View view, int pos, long id)
{
final String itemSelected = parent.getItemAtPosition(pos).toString();
if (valueEntered.getText().length() == 0)
{
valueEntered.setText(String.valueOf(0));
}
if (itemSelected.equals("Stones"))
{
float valueInput = Float.parseFloat(valueEntered.getText().toString());
Toast.makeText(parent.getContext(), "The scale is " +
parent.getItemAtPosition(pos).toString(), Toast.LENGTH_LONG).show();
valueEntered.setText(String.valueOf(convertSToK(valueInput)));
}
}
I really need some help, many thanks,
Davide Sousa
Use a dialog like the spinner:
and then show the dialog with
b1().show();