开发者

when i click on "DONE" button on softkeybord how to go next activity android

when i click on softkeyboard my keyboard getdown or hide but i want to go to next activity when i click on "done " button on keyboard of android.so how to do it?

and my next qus is if i have 2 edit box in my layout when i click on first edit box then i开发者_开发知识库n my soft keyboard "next " would appear for going to next text box and when i go to second text box it change to "done". thanks in advance....

x


Its is better to add some button in the layout as all android phones dont provide a consistent behaviour when using imeoptions.

This seems to be a bug. Different manufacturers make a customized keyboard for their phone which may not completely behave as the android standard keyboard. This issue has been raised before. Most people overcome this issue by either overiding the onKey event or using a TextWatcher class. A bug has been filed about this

http://code.google.com/p/android/issues/detail?id=2882

You can use a listener to check for imeoptions

incomeInput.setOnEditorActionListener(new EditText.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE){
                    //Do your stuff here
                    return true;  // mark the event as consumed
                }
            return false;
            }
} 


You need to implement OnEditorActionListener interface.

Code looks like :

public class Main extends Activity implements OnEditorActionListener {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main1);
}

public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

    if (actionId == EditorInfo.IME_ACTION_DONE) {
        startActivity(new Intent());
        return true;
    }
    return false;
}}


Use setOnKeyListener with your second EditText and in onKey method do something like this.

@Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{       
    // TODO Auto-generated method stub
   if(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)
    performYourAction();    

  return false;
}

I hope it will be helpfull for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜