我陷入了困境。我正在尝试使用微调器来让用户选择位置。我正在通过 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);
}
}