0
我被困在一個局面。我正在嘗試使用旋鈕來讓用戶選擇位置。我通過sqlite填充spinners。這個想法有時候會有一個國家,省份,城市和分區,但是任何字段都可以是空白的(如果沒有填入數據庫)。Android開發人員 - 微調
我想紡紗是「隱藏的」,如果他們沒有存儲在數據庫中的值。然而,只有「下一步」(例如:國家到省)被隱藏,並不是所有的「其他步驟」(城市和子區域)
我希望我足夠清楚,如果不是我可以澄清。
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);
}
}