Question

how to make a text change you from one screen to another. Not button, text, I just need to know what to add in the .java

Was it helpful?

Solution

I suppose you are referring to changing from one screen (activity) to another by typing something and not by clicking a button. If that is the case use TextWatcher and on change check for your string (or command) and move to next screen. Something like.

textView.addTextChangedListener(new TextWatcher(){
    public void afterTextChanged(Editable s) {}
    public void beforeTextChanged(CharSequence s, int start, int count, int after){}
    public void onTextChanged(CharSequence s, int start, int before, int count){
        if("second".equalsIgnoreCase(s)){
            Intent intent = new Intent(this, SecondActivity.class);
            startActivity(intent);
                    }
    }
}); 

OTHER TIPS

step 1 : pass text from screen 1 to screen 2
step 2 : in OnCreate() method of screen 2 , recieve and change the text according to your requirement

but Personally i feel you want to display some screen info for every screen is it ??

Maybe you want to use a TextView instead of a Button...in that case, make your TextView clickable:true in your xml and then you can set an onClickListener to it. Either by TextView.setOnClickListener(new OnClickListener....) in java, or by android:onClick in xml. Just like for a button.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top