jason flanagan
jason flanagan

Reputation: 117

how to search a string for a character and no where it is in the string then change it

OK, so i am trying to create my own app that takes text you type in and then converts it to a different language that i have made up, how would i search the EditText for the first letter and then change it, then keep doing that for how long the user types?

I am new to programming so i am sorry if its simple, i no it has something to do with arrays right?

public class MainMenu extends Activity {
    Button PasswordSetup;
    boolean ShowPasswordBTN = false;
    EditText UserInput,UserOutput;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.mainmenu);

        PasswordSetup = (Button) findViewById(R.id.SetUpPassword);
        UserInput = (EditText) findViewById(R.id.UserInput);
        //What the user types
        UserOutput = (EditText) findViewById(R.id.UserOutput);
        //What i whnt it toshow in after converting the text

        SharedPreferences GetPasswordBTN = getSharedPreferences("#.#.#.#", Context.MODE_PRIVATE);
        ShowPasswordBTN = GetPasswordBTN.getBoolean("PasswordPres",false);

        if(ShowPasswordBTN==true){
           PasswordSetup.setVisibility(View.GONE);
        }

        UserInput.getText();
           //I want to do it here

        PasswordSetup.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent GoToPasswordSetup = new Intent(getApplicationContext(),PasswordSetup.class);
                startActivity(GoToPasswordSetup);
                finish();
            }
        });
    }
}

this is what im changing the letters to

A=C B=D C=E D=F E=G F=H G=I H=J I=K J=L K=M L=N M=O N=P O=Q P=R Q=S R=T S=U T=V U=W V=X W=Y X=Z Y=B Z=A

Upvotes: 0

Views: 304

Answers (1)

AndroidEnthusiast
AndroidEnthusiast

Reputation: 6657

You can add a text watcher to your Edit text.

"How would i search the EditText for the first letter and then change it, then keep doing that for how long the user types?"

 myEditText.addTextChangedListener(new TextWatcher() {
    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        //check the sequence and do something
    }

    @Override
    public void afterTextChanged(Editable arg0) {
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }
});

Upvotes: 1

Related Questions