Android开发人员-微调器

Android开发人员-微调器,android,spinner,Android,Spinner,我陷入了困境。我尝试使用微调器,以便用户选择位置。我正在通过sqlite填充微调器。其想法是,有时会有一个国家、省、市和分区,但任何字段都可以为空(如果数据库中没有填充) 如果微调器没有存储在数据库中的值,我希望它们被“隐藏”。但是,只有“下一步”(例如:从国家到省)是隐藏的,而不是所有的“其他步骤”(城市和分区) 我希望我说得足够清楚,如果不清楚,我可以澄清 public void onItemSelected(AdapterView<?> parent, View view, i

我陷入了困境。我尝试使用微调器,以便用户选择位置。我正在通过sqlite填充微调器。其想法是,有时会有一个国家、省、市和分区,但任何字段都可以为空(如果数据库中没有填充)

如果微调器没有存储在数据库中的值,我希望它们被“隐藏”。但是,只有“下一步”(例如:从国家到省)是隐藏的,而不是所有的“其他步骤”(城市和分区)

我希望我说得足够清楚,如果不清楚,我可以澄清

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) 
{

    if (parent.getId() == R.id.spinner_query_country)
    {
        country.selected = (class_location)country.spinner.getSelectedItem();
        get_province();
    }
    else if (parent.getId() == R.id.spinner_query_province)
    {
        province.selected = (class_location)province.spinner.getSelectedItem();
        get_city();
    }
    else if (parent.getId() == R.id.spinner_query_city)
    {
        city.selected = (class_location)city.spinner.getSelectedItem();
        get_sub_area();
    }
    else if (parent.getId() == R.id.spinner_query_sub_area)
    {
        sub_area.selected = (class_location)sub_area.spinner.getSelectedItem();
    }

}

public void onNothingSelected(AdapterView<?> parent) 
{
    // TODO Auto-generated method stub
}

void get_country()
{       
    make_spinner(country, db.getAll("SELECT * FROM country"));
}
void get_province()
{   
    make_spinner(province, db.getAll("SELECT * FROM province WHERE country_key=" + country.selected._key));
}
void get_city()
{   
    make_spinner(city, db.getAll("SELECT * FROM city WHERE province_key=" + province.selected._key));
}
void get_sub_area()
{   
    make_spinner(sub_area, db.getAll("SELECT * FROM sub_area WHERE city_key=" + city.selected._key));
}


void make_spinner(_structure structure, List<class_location> location_list)
{
    if (location_list.size() > 0)
    {
        class_location location_array[] = location_list.toArray(new class_location[location_list.size()]);

        ArrayAdapter<?> adapter = new ArrayAdapter<Object>(this, android.R.layout.simple_spinner_item, location_array);
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        structure.spinner.setAdapter(adapter);
        structure.spinner.setVisibility(View.VISIBLE);
        structure.textview.setVisibility(View.VISIBLE);
    }
    else
    {
        structure.spinner.setAdapter(null);
        structure.spinner.setVisibility(View.GONE);
        structure.textview.setVisibility(View.GONE);
    }

}
public void已选择(AdapterView父视图、视图视图、整数位置、长id)
{
if(parent.getId()==R.id.spinner\u query\u country)
{
country.selected=(class_location)country.spinner.getSelectedItem();
获得省();
}
else if(parent.getId()==R.id.spinner\u query\u省)
{
province.selected=(类_位置)province.spinner.getSelectedItem();
获取城市();
}
else if(parent.getId()==R.id.spinner\u query\u city)
{
city.selected=(类_位置)city.spinner.getSelectedItem();
获取子区域();
}
else if(parent.getId()==R.id.spinner\u query\u sub\u区域)
{
sub_area.selected=(类位置)sub_area.spinner.getSelectedItem();
}
}
未选择公共无效(AdapterView父级)
{
//TODO自动生成的方法存根
}
void get_country()
{       
make_微调器(country,db.getAll(“SELECT*FROM country”);
}
void get_province()
{   
生成_微调器(省,db.getAll(“选择*来自省,国家/地区设置键=“+country.selected._键));
}
void get_city()
{   
生成_微调器(城市,db.getAll(“选择*来自省所在城市_键=“+province.selected._键));
}
void get_sub_区域()
{   
制作微调器(sub_area,db.getAll(“选择*从sub_area,其中city_key=“+city.selected._key));
}
void make_微调器(_结构,列表位置_列表)
{
if(location_list.size()>0)
{
class_location location_array[]=location_list.toArray(新class_location[location_list.size());
ArrayAdapter=新的ArrayAdapter(这是android.R.layout.simple\u微调器\u项,位置\u数组);
setDropDownViewResource(android.R.layout.simple\u微调器\u下拉菜单\u项);
结构.微调器.设置适配器(适配器);
structure.spinner.setVisibility(View.VISIBLE);
structure.textview.setVisibility(View.VISIBLE);
}
其他的
{
structure.spinner.setAdapter(null);
structure.spinner.setVisibility(View.GONE);
structure.textview.setVisibility(View.GONE);
}
}

您只隐藏了一个微调器,而不是所有微调器,这仅仅是因为您在
make_spinner()
上设置了可见性,并且您只在所选的
微调器上检查了一步(如果有严格要求)。为了清楚起见,您的代码设置了一个方法上组件的可见性或不可见性,而“其他步骤”从未调用该方法

附言:你的代码有点凌乱,没有遵循安卓的惯例或准则。这很糟糕。尝试查看一些指导原则,帮助您的合作者:)