我的应用程序是最初显示商店标签,在加载后从服务中获取所有商店名称&适合自动完成,然后向用户显示自动完成块,用户可以选择商店。一旦他选择了对用户可见的商店登录区块。
我的问题是用户选择商店&输入用户名&密码,点击登录按钮,将屏幕旋转到另一侧或当方向改变为纵向或明智的横向时,它只显示自动完成块,它没有显示登录块
这意味着。当方向改变时,它会重新创建活动,但不会转到Autocomplete setOnItemClickListener
清单文件我添加了这一行
<activity android:name="com.pearson.lsmobile.LoginActivity" android:label="@string/title" android:configChanges="orientation|screenSize|keyboardHidden" android:screenOrientation="unspecified"> </activity>
我的代码是:
public class LoginActivity extends ShopMainDefaultActivity {
@Nullable @InjectView(R.id.login_button) Button loginButton;
@Nullable @InjectView(R.id.username_text) EditText usernameText;
@Nullable @InjectView(R.id.password_text) EditText passwordText;
@Nullable @InjectView(R.id.remember_check) CheckBox rememberCheck;
@Inject ECollegeApplication app;
@Inject SharedPreferences prefs;
@Nullable @InjectView(R.id.txtShopFilter) AutoCompleteTextView txtShopFilter; //Inject
@Nullable @InjectView(R.id.filter_box) LinearLayout filter_box;
@Nullable @InjectView(R.id.login_box) LinearLayout loginBox;
private ArrayAdapter<String> adapter; //AutoComplete array adapter
protected ECollegeClient client;
private Map<String,Shop> mapShop = new HashMap<String,Shop>();
private class DoneOnEditorActionListener implements OnEditorActionListener {
public boolean onEditorAction(TextView textView, int actionID, KeyEvent event) {
if (actionID == EditorInfo.IME_ACTION_DONE) {
InputMethodManager imm = (InputMethodManager)textView.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(textView.getWindowToken(), 0);
return true;
}
return false;
}
}
private void loadShops(){
buildService(new FetchAllUniversities()).execute();
}
public void onServiceCallSuccess(FetchAllUniversities service) {
mapUniversity = service.getResult();
loginBox.setVisibility(View.GONE); // Hide login view
displaySchool();
overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
}
/*
* This method load the universities into array adapter
*/
private void displaySchool(){
filter_box.setVisibility(View.VISIBLE);
adapter = new ArrayAdapter<String>(LoginActivity.this,android.R.layout.simple_list_item_1,new ArrayList<String>(mapShop.keySet())); //Initialize array adapter
txtShopFilter.setAdapter(adapter);// set adapter for the auto complete fields
txtShopFilter.setThreshold(1); // specify the minimum type of characters before drop-down list is shown
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
client = app.getClient();
setContentView(R.layout.login);
filter_box.setVisibility(View.GONE);
if (!isOnline()) { //
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.app_name);
builder.setMessage(R.string.e_no_network_connection);
builder.setIcon(android.R.drawable.ic_dialog_alert);
builder.setCancelable(false);
builder.setPositiveButton(android.R.string.ok,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
return;
}else{
loadShops();
}
usernameText.setOnEditorActionListener(new DoneOnEditorActionListener());
passwordText.setOnEditorActionListener(new DoneOnEditorActionListener());
rememberCheck.setTextColor(getResources().getColor(R.color.color_primary));
txtShopFilter.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
loginBox.setVisibility(View.VISIBLE);
txtShopFilter.setEnabled(false);
}
});
}
请帮帮我
任何解决方案?
答案 0 :(得分:1)
在方向更改时,正在重新创建活动
因此,您需要在活动被销毁之前保存数据,并在重新创建后检索
您可以在onSaveInstanceState
中保存自动填充选择的状态,并检索onCreate
或onRestoreInstanceState
试试这个link