更改第一个微调器时,我正在尝试更改第二个微调器。这就是我尝试过的。
spinnerBid = findViewById(R.id.profile_spinner_bid);
spinnerBid.setAdapter(null);
unitBAdapter = new UnitBAdapter(ProfileActivity.this, getUnitBs(aId));
spinnerBid.setAdapter(unitBAdapter);
int positionB = -1;
for (int i = 0; i < getUnitBs(aId).size(); i++) {
if (getUnitBs(aId).get(i).getBId() == bId) {
positionB = i;
}
}
spinnerBid.setSelection(positionB);
unitBAdapter.notifyDataSetChanged();
答案 0 :(得分:0)
您可以根据需要在onCreate()中执行以下代码,
spinner1 = findViewById(R.id.spinner1);
spinner2 = findViewById(R.id.spinner2);
String[] s1 = {"abc", "def", "ghi", "jkl"};
String[] s2 = {"mno", "pqr", "stu", "vwx"};
ArrayAdapter<String> adapter1 =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, s1);
ArrayAdapter<String> adapter2 =new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, s2);
spinner1.setAdapter(adapter1);
spinner2.setAdapter(adapter2);
spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
//here you can write your code for your requirements like,
// if in spinner1 position 1 is selected then in spinner2 set position to 1 or anything you want
if(position==0){
spinner2.setSelection(0);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
我希望这对您有帮助。