は、私は現在、私のAndroidアプリケーションのためのアカウント管理活動に取り組んでいると私はスピナーからsetSelection()方法が接続OnItemSelectedListenerをトリガしない理由を考え出すのトラブルを抱えているスピナーは言い。Spinner.setSelectionがOnItemSelectedListenerトリガされません正しく
これは私が現在持っているものです。
のonCreate()メソッド:
/** OnItemSelectedHandler for the Country Spinner */
mCountrySpinner.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View view,
int pos, long id) {
Log.i(TAG, "onCountrySelected() was called, position : " + pos);
mProvinces = new ArrayList<String>();
mProvincesCode = new ArrayList<String>();
mXML.parseResponse(FileManager.getInstance().getPortalOptions());
for (int i = 0; i < mXML.getCountry(pos).sizeProvinces(); i++){
mProvinces.add(mXML.getCountry(pos).getProvince(i).getLabel(mLanguage));
mProvincesCode.add(mXML.getCountry(pos).getProvince(i).getCode());
}
mProvinceArrayAdapter = new ArrayAdapter<String>(ManageAccountActivity.this,
android.R.layout.simple_spinner_item, mProvinces);
mProvinceArrayAdapter.setDropDownViewResource(
android.R.layout.simple_spinner_dropdown_item);
mProvinceSpinner.setAdapter(mProvinceArrayAdapter);
}
public void onNothingSelected(AdapterView<?> arg0) {
// Do Nothing ...
}
});
そして再び:リスナースピナーの結合を示しているアクティビティの作成時に呼び出されたinitializeUI()メソッドから
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.account_management);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
retreiveLanguage();
initializeUI();
// Vérification si l'usager est déjà connecté
Globals appState = ((Globals) this.getApplication());
boolean userLoggedIn = appState.isUserLoggedIn();
boolean userInfoAvailable = appState.isUserInfoAvailable();
if (userLoggedIn && userInfoAvailable) {
fillUI();
}
}
関連のある行fillUIメソッド()からの別のカップルライン:
Log.i(TAG, "Setting country based on user information.");
((Spinner) findViewById(R.id.spin_country))
.setSelection(mCountriesCode.indexOf(mUser.getCountry()));
// TODO : Fix Provinces and States not being changed accordingly
Log.i(TAG, "Setting province based on user information.");
((Spinner) findViewById(R.id.spin_province))
.setSelection(mProvincesCode.indexOf(mUser.getProvince()));
私はfillUI()メソッドで選択をセットした直後にOnItemSelectedListenerが呼び出されることを期待していますが、それは実行時に起こっていることではありません:S
私のLogCatの抽出は、選択は国スピナーに適用されます。
I/ManageAccountActivity(28108):ユーザー情報に基づいて国を設定します。
I/ManageAccountActivity(28108):ユーザー情報に基づいて地域を設定します。
I/ManageAccountActivity(28108):onCountrySelected()、位置と呼ばれていました:実験として1
、私も私の活動のONSTART方法が、そののdidnにfillUI()の呼び出しを入れてみました」アプリケーションがどのように反応したかを変更します。
ご指摘いただきありがとうございました。
、OnneremSelectedListenerは、スピナーで何らかのアクションを実行したときにのみ起動されます。 –
私はそれを変更します...選択を0から1に変更すると変更されないと考えられますか? –