1

My application is Initially show Shop label ,after load fetch all shops name from service & fit on autocomplete , then show autocomplete block to user , user can select shop. Once he select shop login block visible to user.

My problem is user select shop & enter username & password , before click login button, rotate screen to other side or when orientation change landscape to portrait or wise verse, it show only autocomplete block,it didn't show login block

That means. when orientation change , it recreate activity, but it didn't go to Autocomplete setOnItemClickListener

Manifest file i added this line

     <activity android:name="com.pearson.lsmobile.LoginActivity" android:label="@string/title" android:configChanges="orientation|screenSize|keyboardHidden" android:screenOrientation="unspecified"> </activity>

My code is :

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

        }
    });
}

please help me

any solutions?

user3391455
  • 51
  • 1
  • 7

1 Answers1

1

On orientation change the activity is being recreated

So you need to save the data before activity being destroyed and retrieve once recreated

Here you can save the state of the autocomplete selection in onSaveInstanceState and retrieve the data in the onCreate or onRestoreInstanceState

Try this link

Community
  • 1
  • 1
BlackBeard
  • 145
  • 6