我正在制作一个 OTPActivity
并且需要实现删除功能,我有以下功能应该被onKey
退格按钮触发。我的想法是我可以getCurrentFocus
用来知道当前正在填充哪些字段,然后requestFocus
用来选择之前的字段,但它似乎不起作用,我有另一个功能goToNext
可以正常工作,所以我很困惑为什么。
我正在读取字节如下:
try(FileInputStream f = new FileInputStream("nameOfFile")){
int readByte = 0;
int mask =0b111;
while((readByte=f.read())!=-1) {
System.out.println(Integer.toBinaryString(readByte & mask));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
但是,当我尝试获取构成数字的 8 位时,有时我会得到 7 位甚至比 8 位更多的位。有人可以帮我解决这个问题吗?我想获得 8 位,以便之后我可以查看前 3 位。我需要它来返回此方法中的字符集。
public void goToPrevious() {
EditText currentFocus = (EditText) getCurrentFocus();
if (currentFocus == otpOne) {
return;
}
if (currentFocus == otpTwo) {
otpOne.requestFocus();
return;
}
if (currentFocus == otpThree) {
otpTwo.requestFocus();
return;
}
if (currentFocus == otpFour) {
otpThree.requestFocus();
return;
}
}
下面是goToNext工作正常的代码。
public void goToNext() {
EditText currentFocus = (EditText) getCurrentFocus();
if (currentFocus == otpOne) {
otpTwo.requestFocus();
return;
}
if (currentFocus == otpTwo) {
otpThree.requestFocus();
return;
}
if (currentFocus == otpThree) {
otpFour.requestFocus();
return;
}
if (currentFocus == otpFour) {
return;
}
}
慕桂英546537
侃侃尔雅
相关分类