在我的应用程序中,我有两个微调器(占用,子占用),其中第一个微调器从一个字符串数组中填充,第二个微调器根据第一个微调器中选择的值填充。
两个微调器的选定值都存储在SQLite数据库中。保存后,用户可以编辑记录,因此在显示要编辑的记录时,我希望在用户上次选择的微调器上显示特定值。
当我尝试这样做时,第一个微调器值设置正确,但我无法设置第二个微调器值。它始终显示该微调器的数组中的第一个值。
以下是在EDIT页面中为微调器赋值的代码:
if (bundlevalue.get(21).equalsIgnoreCase("Salaried")) {
spin_occupation.setSelection(0);
if(bundlevalue.get(22).equalsIgnoreCase("Others"))
{
spin_subOccu.setSelection(4);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Police"))
{
spin_subOccu.setSelection(1);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Legal Profession"))
{
spin_subOccu.setSelection(2);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Central/State Government"))
{
spin_subOccu.setSelection(3);
occuSubArrayAdap.notifyDataSetChanged();
}
else
{
spin_subOccu.setSelection(0);
occuSubArrayAdap.notifyDataSetChanged();
}
}
else if (bundlevalue.get(21).equalsIgnoreCase(
"Self employed non professional")) {
spin_occupation.setSelection(1);
if(bundlevalue.get(22).equalsIgnoreCase("Others"))
{
spin_subOccu.setSelection(5);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Travel Agent /Telecommunication Service/Tours&Travels"))
{
spin_subOccu.setSelection(1);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Restaurant/Hotels/Resorts"))
{
spin_subOccu.setSelection(2);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Retail Stores"))
{
spin_subOccu.setSelection(3);
occuSubArrayAdap.notifyDataSetChanged();
}
else if(bundlevalue.get(22).equalsIgnoreCase("Money Changers/Money Lenders/Real Estate"))
{
spin_subOccu.setSelection(4);
occuSubArrayAdap.notifyDataSetChanged();
}
else
{
spin_subOccu.setSelection(0);
occuSubArrayAdap.notifyDataSetChanged();
}
我的代码出了什么问题?有人可以解释一下吗?
请帮忙!
提前致谢!
答案 0 :(得分:0)
将OnItemClickListener()设置为super_spinner,当选择任何项目时,尝试更改传递给sub_spinner的Adapter的值。
super_spinner.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
// change adapter values of sub_spinner here !!
}
});
答案 1 :(得分:0)
更新第一个微调器setOnItemSelectedListener
中第二个微调器的数组列表spinner1.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
// TODO Auto-generated method stub
string str=spinner1.getSelectedItem().toString();
if(str.equals("spinner item"))//spinner item is selected item of spinner1
{
ArrayAdapter<String>adapter1 = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, array1);
spinner2.setAdapter(adapter1);//pass this updated adapter1 to second spinner
}else if{
ArrayAdapter<String>adapter1 = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, array2);
spinner2.setAdapter(adapter2);
}
}