Answer the question
In order to leave comments, you need to log in
Dependencies between two spinners and transfer of position to the second spinner, how to implement?
There are two spinners:
String[] outputChannel = {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"};
String[] sensorType = {"1", "2", "3", "4"};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_data_input, container, false);
// адаптер спинера - Выходные каналы 1-12
ArrayAdapter<String> AdapterOutputChannel = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, outputChannel);
AdapterOutputChannel.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
final Spinner SpinnerOutputChanel = (Spinner) view.findViewById(R.id.OutputChannelSpinner);
SpinnerOutputChanel.setAdapter(AdapterOutputChannel);
// устанавливаем обработчик нажатия
SpinnerOutputChanel.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Position = " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
// адаптер спинера - Тип датчика 1-4
ArrayAdapter<String> AdapterSensorType = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item, sensorType);
AdapterSensorType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner SpinnerSensorType = (Spinner) view.findViewById(R.id.SensorTypeSpinner);
SpinnerSensorType.setAdapter(AdapterSensorType);
// устанавливаем обработчик нажатия
SpinnerSensorType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getActivity(), "Position = " + position, Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
return view;
}
[1, 3, 1, 2, 2, 2, 1, 1, 4, 3, 3, 3]
in which the value is from 1 to 4. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question