Question

I know this question is asked before here. But there was no solution found.

What I want is to have Next,Previous and Done buttons above the keyboard ( I know its mimicking iphone keyboard,but I m helpless its requirement ).

Like this : here

Now what I have tried is ::

So,I took three buttons in one layout and assigned property android:alignParentBottom="true" and in manifest add android:windowSoftInputMode="adjustResize".

Which look like this ::
enter image description here

And What I did to move to and from using "next" "previous button is :

int next=1,prev=1;
public boolean onTouch(View arg0, MotionEvent arg1){                
            prev=next=1;                
            return false;
        }
});
edUserName.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(View arg0, MotionEvent arg1){
            prev=next=2;
            return false;
        }
});
edCity.setOnTouchListener(new View.OnTouchListener(){
        public boolean onTouch(View arg0, MotionEvent arg1){
            prev=next=3;
            return false;
        }
 });
btnNext.setOnClickListener(new View.OnClickListener(){          
        public void onClick(View arg0) {                
            if(next==1){    
                next++;     
                prev++;
                edUserName.requestFocus();                          
            }else if(next==2){
                next++;
                prev++;
                edCity.requestFocus();   
            }
        }
});
btnPrevious.setOnClickListener(new View.OnClickListener(){
        public void onClick(View arg0) {                
            if(prev==2){
                prev--;
                next--;
                edName.requestFocus();
            }else if(prev==3){
                prev--;
                next--;
                edUserName.requestFocus();
            }
        }
 });

This allows me to move to and fro using next and previous buttons.

Now problems ::

  1. I know its little dirty. Please guide if any better way to move to and fro using next and previous buttons.

  2. I want to show buttons only when keyboard is visible otherwise hide them. How can I do this.?

  3. "Done" Button, i need to hide keyboard it its showing, for which i tried this, But, its not working sometimes. :

    InputMethodManager imm = (InputMethodManager)getSystemService (Context.INPUT_METHOD_SERVICE);

    if(imm != null){

    imm.toggleSoftInput(0, InputMethodManager.HIDE_IMPLICIT_ONLY);

    }

  4. How to hide the suggestions.

Please help me in this.

Thanks.

No correct solution

OTHER TIPS

I know you say it's a requirement, but those requirements just aren't going to be possible. Firstly, there's no callback or method to check or watch the visibility of the input method. There are some hacks out there that people will suggest, but they're just that -- hacks. You shouldn't rely on them.

Secondly, as for your focus traversal, fortunately Android has pretty good built in support for that sort of thing. Look at the nextFocusDown and similar attributes on TextView/EditText. In most cases you don't even have to specify these as Android is quite good at figuring out the right order for you. If you need to do it programmatically, you can use the requestFocus() method:

editText.requestFocus(View.FOCUS_DOWN);

Or you can use FOCUS_UP to go to the previous view.

EDIT: Also, you can use the attribute inputType="text|textNoSuggestions" to get rid of the suggestions bar on most input methods (although they are not required to respect it, and many don't).

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