私のAndroidアプリには、ユーザーにさまざまな州名を提案するautocompletetextviewフィールドがあります。コードは次のとおりです。
ArrayAdapter<String> state_adapter=new ArrayAdapter<String>(this, android.R.layout.select_dialog_item,state);
actv_state=(AutoCompleteTextView)findViewById(R.id.edt_state);
actv_state.setThreshold(1);
actv_state.setAdapter(state_adapter);
次に、この方法で TextWatcher を使用して、この状態の値を文字列で取得します。
TextWatcher state_text=new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
// TODO Auto-generated method stub
str_state=actv_state.getText().toString();
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
};
actv_state.addTextChangedListener(state_text);
この後、選択した州に基づいて別のオートコンプリートテキストビューに都市名を表示しようとしています.選択した州に基づいて都市名を表示するには、このコードをどこに置くべきかわかりません????
if(str_state.equalsIgnoreCase("MADHYA PRADESH"))
{
ArrayAdapter<String> mp_city_adapter=new ArrayAdapter<String>(this, android.R.layout.select_dialog_item,mp_city);
actv_city=(AutoCompleteTextView)findViewById(R.id.app_city);
actv_city.setThreshold(1);
actv_city.setAdapter(mp_city_adapter);
}
if(str_state.equalsIgnoreCase("CHATTISGARH"))
{
ArrayAdapter<String> mp_city_adapter=new ArrayAdapter<String>(this, android.R.layout.select_dialog_item,mp_city);
actv_city=(AutoCompleteTextView)findViewById(R.id.app_city);
actv_city.setThreshold(1);
actv_city.setAdapter(mp_city_adapter);
}
どうすればいいですか?? 私は理解できないようです!どなたか解決策をご存じの方がいらっしゃればお願いします!! ありがとう!