3 回答

TA貢獻1850條經驗 獲得超11個贊
您還需要將偵聽器設置為 edt2
edt2.addTextChangedListener(this);
只需更換
@Override
public void afterTextChanged(Editable editable) {
if(edt1.getText().hashCode() == editable.hashCode()){
if (edt1.length() == 2) {
edt2.requestFocus();
}
}
else if( edt2.getText().hashCode() == editable.hashCode()){
if (edt2.length() == 2) {
edt3.requestFocus();
}
}
}

TA貢獻1810條經驗 獲得超4個贊
XML 文件沒有問題。只需在 MainActivity.java 中嘗試以下代碼
將 TextChangedListener 添加到第二個編輯文本
edt2.addTextChangedListener(this);
在 textwatcher 的 onTextChanged 方法中插入以下代碼
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(edt1.hasFocus())
{
if(edt1.getText().toString().length()==2) //size as per your requirement
{
edt2.requestFocus();
}
}
if(edt2.hasFocus())
{
if(edt2.getText().toString().length()==2) //size as per your requirement
{
edt3.requestFocus();
}
}
}
@Override
public void afterTextChanged(Editable editable) {
}
我希望這個答案能解決你的問題:)

TA貢獻1772條經驗 獲得超6個贊
XML 文件沒有問題。只需在 MainActivity.java 中嘗試以下代碼
將 TextChangedListener 添加到第二個編輯文本
edt2.addTextChangedListener(this);
在 textwatcher 的 onTextChanged 方法中插入以下代碼
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(edt1.hasFocus())
{
if(edt1.getText().toString().length()==2) //size as per your requirement
{
edt2.requestFocus();
}
}
if(edt2.hasFocus())
{
if(edt2.getText().toString().length()==2) //size as per your requirement
{
edt3.requestFocus();
}
}
}
@Override
public void afterTextChanged(Editable editable) {
}
我希望這個答案能解決你的問題:)
添加回答
舉報