开发者

Set cursor from EditText1 to EditText2

I want to move the cursor from an EditText1 to an EditText2 when on button action that will reset all EditTexts, I tried this but it didn't work:

final Button button2 = (Button) findViewById(R.id.button2);

 button2.setOnClickListener(new View.OnClickListener() {
     public void onClick(View开发者_Python百科 v) {

         vol.setText("");
         kil.setText("");
         cons.setText("");

         Editable e = vol.getText();
         int position = vol.length();
         Selection.setSelection(e,position);
     }
     });

Any idea how to resolve this problem?


Use the type ahead sense for your EditText. Look for .focused or .setFocus, etc. I have never done what you're trying to do but I'd start there.


requestFocus() can solve the problem, I add this function in my .java file and it works :). Example:

vol = (EditText) findViewById(R.id.volume2);
vol.requestFocus();

If we want to set the cursor on the "volume2" EditText.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜