I'm trying to pass the value of a spinner into a different fragment so that it can be used in a different fragment to convert it to a different unit. I have the code here. I have an onitemselected method which takes the value of the spinner and displays it at the bottom of the application.
Any help would be appreciated.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_1, container, false);
String[] values =
{"Select Units:", "Miles", "Kilometers", "Meters", "Yards",};
final Spinner spinner = (Spinner) view.findViewById(R.id.spinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values);
adapter.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner.setAdapter(adapter);
spinner.setOnItemSelectedListener(this);
String[] values1=
{"Select Units:", "Miles", "Kilometers", "Meters", "Yards",};
Spinner spinner1 = (Spinner) view.findViewById(R.id.spinner1);
ArrayAdapter<String> adapter1 = new ArrayAdapter<String>(this.getActivity(), android.R.layout.simple_spinner_item, values1);
adapter1.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
spinner1.setAdapter(adapter1);
spinner1.setOnItemSelectedListener(this);
button1 =view.findViewById(R.id.button_confirm);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CharSequence input = spinner.
}
});
return view;
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
String text = parent.getItemAtPosition(position).toString();
Toast.makeText(parent.getContext(),text,Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}