我是android中微调的新手。我需要在一个活动中使用4个多个微调器。每两个微调器拥有相同的字符串数组。因此,我想找到所有微调器的元素位置,并将该位置存储在单独的字符串对象中。
所有答案都是合理的。
private String s1, s2, s3, s4;
ArrayAdapter<CharSequence> adapterList1 = ArrayAdapter.createFromResource(this, R.array.list1, android.R.layout.simple_spinner_item);
adapterCredit.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
/* List1 array has "1,2,3,4,5" */
ArrayAdapter<CharSequence> adapterList2 = ArrayAdapter.createFromResource(this, R.array.list2, android.R.layout.simple_spinner_item);
adapterGrade.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
/* List2 array has "Chennai, Delhi, Hyderabad, Kolkata, Mumbai" */
//Spinner for list 1
spinner1 = findViewById(R.id.spinner1);
spinner3 = findViewById(R.id.spinner3);
spinner1.setAdapter(adapterList1);
spinner3.setAdapter(adapterList1);
//Spinner for list 2
spinner2 = findViewById(R.id.spinner2);
spinner4 = findViewById(R.id.spinner4);
//SetAdapter
spinner2.setAdapter(adapterList2);
spinner4.setAdapter(adapterList2);
//ItemSelectedListener
spinner1.setOnItemSelectedListener(this);
spinner2.setOnItemSelectedListener(this);
spinner3.setOnItemSelectedListener(this);
spinner4.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
/* Need to store the list value in String object */
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}