gpt4 book ai didi

android - onConfigurationChanged 不去监听

转载 作者:行者123 更新时间:2023-11-30 03:01:47 26 4
gpt4 key购买 nike

我的应用程序最初是显示商店标签,从服务中加载获取所有商店名称并适合自动完成后,然后向用户显示自动完成 block ,用户可以选择商店。一旦他选择了用户可见的商店登录 block 。

我的问题是用户选择商店并输入用户名和密码,在点击登录按钮之前,将屏幕旋转到另一边,或者当方向将横向更改为纵向或智慧诗时,它只显示自动完成 block ,没有显示登录 block

意思是。当方向改变时,它会重新创建 Activity ,但不会转到 Autocomplete setOnItemClickListener

list 文件我添加了这一行

     <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);

}
});
}

请帮帮我

有什么解决办法吗?

最佳答案

在方向改变时正在重新创建 Activity

所以你需要在 Activity 被销毁之前保存数据并在重新创建后检索

在这里,您可以在 onSaveInstanceState 中保存自动完成选择的状态,并在 onCreateonRestoreInstanceState 中检索数据

试试这个 link

关于android - onConfigurationChanged 不去监听,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22403615/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com