如何将焦点从一个edittext更改为另一个 [英] how to change the focus from one edittext to another

查看:74
本文介绍了如何将焦点从一个edittext更改为另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表单设计中有2个edittext。我想要实现的是,在键入几个字符后的第一个edittext中,例如我输入abc,焦点应该自动转移到下一个edittext

i使用下面的代码但是不能正确

 gtin =(EditText)findViewById(R.id.editText1); 
expiry =(EditText)findViewById(R.id.editText2);
String sgtin = gtin.getText()。toString();
if (sgtin.length()== 3){
expiry.findFocus();
// expiry.requestFocus();
}

解决方案

你需要实现一个用于文本更改事件的监听器,参见示例:

http://www.mysamplecode.com/2012/06/android-edittext-text-change-listener.html [ ^ ]

要设置对editext的关注,请尝试:

 editText.requestFocus(); 


i have 2 edittext in my form design. what i want to acheive is that in the first edittext after typing few characters say for example i type "abc", the focus should automatically shift to the next edittext
i used the following code but cant get it right

gtin=(EditText) findViewById(R.id.editText1);
		expiry=(EditText) findViewById(R.id.editText2);
		String sgtin=gtin.getText().toString();
		if(sgtin.length()==3){
			expiry.findFocus();
			//expiry.requestFocus();
		}

解决方案

You need to a implement a listener for text change event, see example:
http://www.mysamplecode.com/2012/06/android-edittext-text-change-listener.html[^]
To set focus on an editext, try:

editText.requestFocus();


这篇关于如何将焦点从一个edittext更改为另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆