私はアンドロイドとジャバの両方に不慣れです。スピナーが選んだ国、州、都市を含むシンプルなアプリを開発しています。ここで、国(インド)を選択しているときに、インドの州のみを取得する必要があると考えてください。そして、任意の州(アンドラプラデシュ)を選択している間、APの都市が次のスピナーに表示されます。誰かがサンプルコードで私を提案できますか?
前もって感謝します
私はアンドロイドとジャバの両方に不慣れです。スピナーが選んだ国、州、都市を含むシンプルなアプリを開発しています。ここで、国(インド)を選択しているときに、インドの州のみを取得する必要があると考えてください。そして、任意の州(アンドラプラデシュ)を選択している間、APの都市が次のスピナーに表示されます。誰かがサンプルコードで私を提案できますか?
前もって感謝します
このロジック(2つのスピナー用)をコードに追加できます。
public void onCreate() {
....
Country[] mCountries = ... ;
final Spinner spinner1 = ...;
final Spinner spinner2 = ...;
spinner1.setAdapter(new ArrayAdapter(mCountries);
spinner1.setOnItemSelectedListener( new OnItemSelectedListener() {
void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Country country = (Country) parent.getAdapter().getItem(position);
spinner2.setAdapter(new ArrayAdapter(country.getStates());
}
void onNothingSelected(AdapterView<?> parent) {
spinner2.setAdapter(null);
}
});
....}