输入编辑文本时焦点被移除
我有一个 EditText
serialText = (EditText) findViewById(R.id.pinText);
现在点击某个按钮,我应该获得焦点来编辑文本来写一些东西。但是,当我单击编辑文本内部进行写入时,焦点被移除,即,无论我输入什么,都不会出现在编辑文本中
这是执行此操作的代码,
public void method(View v) {
arrowButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialNumber = serialText.getText().toString();
if (serialNumber.equals("")) {
} else {
}
} }...
在这里,如果我不输入任何内容,则 if 循环不会出现任何问题,但其他部分没有发生同样的情况。
你能帮我吗?
这是我的完整代码
public void onClick(View v) {
if (v.getId() == R.id.pinBtn) {
arrowButton = (Button) findViewById(R.id.arrowBtn);
serialText = (EditText) findViewById(R.id.pinText);
serialText.setVisibility(View.VISIBLE);
arrowButton.setVisibility(View.VISIBLE);
//serialNumber = serialText.getText().toString();
arrowButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialNumber = serialText.getText().toString();
if (serialNumber.equals("")) {
Toast.makeText(getApplicationContext(),
"Please enter the serial number",
Toast.LENGTH_SHORT).show();
}
else {
isRegularSerialNumber(serialNumber);
String encodedserialNumber = Base64.encodeToString(
serialNumber.getBytes(), Base64.DEFAULT);
receiveSerialData(encodedserialNumber);
if (serialResponse.equals("Validated Successfully!")) {
showAudio(v);
} else {
Toast.makeText(getApplicationContext(),
"Invalid Serial Number", Toast.LENGTH_SHORT)
.show();
}
}
}
});
}
}
谢谢
I have an EditText
serialText = (EditText) findViewById(R.id.pinText);
Now onclick of somebutton, I should get the focus to edit text to write something. But when I click inside of edit text to write, focus is getting removed, i.e., whatever i type does not appear in the edit text
This is the code to do that,
public void method(View v) {
arrowButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialNumber = serialText.getText().toString();
if (serialNumber.equals("")) {
} else {
}
} }...
Here if I don't type anything it comes to if loop without any problem, but samething is not happening for else part.
Can you please help me?
This is my full code
public void onClick(View v) {
if (v.getId() == R.id.pinBtn) {
arrowButton = (Button) findViewById(R.id.arrowBtn);
serialText = (EditText) findViewById(R.id.pinText);
serialText.setVisibility(View.VISIBLE);
arrowButton.setVisibility(View.VISIBLE);
//serialNumber = serialText.getText().toString();
arrowButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
serialNumber = serialText.getText().toString();
if (serialNumber.equals("")) {
Toast.makeText(getApplicationContext(),
"Please enter the serial number",
Toast.LENGTH_SHORT).show();
}
else {
isRegularSerialNumber(serialNumber);
String encodedserialNumber = Base64.encodeToString(
serialNumber.getBytes(), Base64.DEFAULT);
receiveSerialData(encodedserialNumber);
if (serialResponse.equals("Validated Successfully!")) {
showAudio(v);
} else {
Toast.makeText(getApplicationContext(),
"Invalid Serial Number", Toast.LENGTH_SHORT)
.show();
}
}
}
});
}
}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我终于解决了问题,问题是当我们在列表视图中保留编辑文本并且尝试在其中写入时,键盘将列表视图向上推。因此,我们需要将属性 android:windowSoftInputMode="adjustPan" 添加到列表视图或清单文件中包含列表视图的活动中。
I solved the problem finally, the problem was when we keep an edit text in the listview and when try to write inside that, keyboard pushes the listview up. So we need to add the property android:windowSoftInputMode="adjustPan" to the listview or to the activity containing the list view in the manifest file.
不要使用
serialNumber.equals("")
,而是尝试将其替换为:或
Instead of using
serialNumber.equals("")
, try replacing it with:or
您发布的代码是
arrowButton
的onClick()
,您应该发布serialText
的onClick()
The code you posted is
onClick()
ofarrowButton
, you should postonClick()
ofserialText