0

I have a simple layout that has a picture at the top, two EditTexts for username and password and finally a login button. When the edit text is tapped to begin typing the layout shifts (As expected to keep the view available for the user) however the layout keeps each iteration of the shift... see pictures below. In addition any time i type anything into the edit text the hint does not disappear and the letters do not disappear either despite backspacing. How do i get this to cease?

![Keyboard shifts view up and the layout is repeated]https://i.stack.imgur.com/kiPGU.jpg ![When text is entered in edit text the cursor remains and text repeats]https://i.stack.imgur.com/O9pGq.jpg

Activity Code

package com.example.ybfe1853.blackwoodscheduling;

import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class LogInActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fragment_container);


        if(findViewById(R.id.activity_log_in_id) != null){

            if(savedInstanceState != null){

                return;
            }

        }

        LogInActivityFragment logInFragment = new LogInActivityFragment();
        getFragmentManager().beginTransaction().add(R.id.fragment_container,logInFragment).commit();
    }

}

Fragment Code package com.example.ybfe1853.blackwoodscheduling;

/**
 * Created by ybfe1853 on 10/6/16.
 */

    import android.app.Fragment;
    import android.content.Intent;
    import android.database.Cursor;
    import android.database.sqlite.SQLiteQueryBuilder;
    import android.os.AsyncTask;
    import android.os.Bundle;

    import android.util.Log;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.EditText;
    import android.widget.ImageView;

public class LogInActivityFragment extends Fragment {
    EditText eMail;
    EditText password;
    String email_value;
    String password_value;
    Button loginButton;
    final String EMAIL_COLUMN = "EMAIL";
    final String PASSWORD = "PASSWORD";

//apps using fragments on devices earlier than honey comb must extend FragmentActivity rather than just fragment//

//savedInstanceState is a Bundle that passes data about the previous instance of the fragment, just in case this fragment is being resumed;

    @Override
//To inflate your fragment's layout inside the current activity, you need to override the onCreateView() method//

    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.activity_log_in, container, false);
        eMail = (EditText) view.findViewById(R.id.email_id);
        password = (EditText) view.findViewById(R.id.password_id);
        loginButton = (Button) view.findViewById(R.id.login_button);


        loginButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                email_value = eMail.getText().toString();
                password_value = password.getText().toString();
                LogInTask login = new LogInTask();
                if (login.doInBackground(email_value, password_value)) {
                    Intent newIntent = new Intent(getActivity(), CustomerAppointmentsActivity.class);
                    startActivity(newIntent);
                }
            }
        });


        return view;
    }

    private class LogInTask extends AsyncTask<String, Integer, Boolean> {
        protected Boolean doInBackground(String... credentials) {
            boolean authenticated = false;
            int password = 1;
            int email = 0;
            String[] credentialParams = new String[]{EMAIL_COLUMN, PASSWORD};
            credentialParams[email] = EMAIL_COLUMN;
            credentialParams[password] = PASSWORD;
            credentials[email] = email_value.replace(" ", "");
            credentials[password] = password_value;

            DBHandler db = new DBHandler(getActivity());
            Cursor cursor;

            cursor = db.getReadableDatabase().rawQuery("SELECT EMAIL, PASSWORD FROM BLACKWOOD_USER " +
              "WHERE EMAIL = ?  AND PASSWORD = ?", new String[]{credentials[email], credentials[password]});

            int rowsReturned = cursor.getCount();
            cursor.moveToFirst();



                if(password_value.equals(cursor.getString(cursor.getColumnIndex("PASSWORD")))){
                    authenticated = true;
                    return authenticated;
                }
            else{
                    return authenticated;
                }

        }


        }

    }

Fragment XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id = "@+id/activity_log_in_id"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".LogInActivity">


    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/login_page_title"

        android:textSize="24dp"
        />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id = "@+id/barberImageContainerId"
        android:src = "@drawable/barberimage"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint = "@string/user_name_hint"
        android:layout_marginTop="75dp"
        android:id = "@+id/email_id"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:hint = "@string/password_hint"
        android:layout_marginTop="75dp"
        android:id = "@+id/password_id"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/login_button_name"
        android:layout_gravity="center"
        android:layout_marginTop="100dp"
        android:id = "@+id/login_button"/>

</LinearLayout>

Fragment Container XML

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout android:id="@+id/fragment_container"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android" />

1 Answers1

0

Add keybord property to your activity . But it will not allowed you to type when your focus is on password edittext . Refer this link adjuest keybord android:windowSoftInputMode="adjustNothing" add this in your activity tag of manifest.xml .

Community
  • 1
  • 1
Gevaria Purva
  • 552
  • 5
  • 15