0

私は状況に行き詰まっています。ユーザーが場所を選択できるように、スピナーを使用しようとしています。私は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);
    }

}
4

1 に答える 1