安卓的EditText返回值相同的内容 [英] Android: EditText returning same value as contents
本文介绍了安卓的EditText返回值相同的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的方法负责插入新记录到数据库表,它被称为当按钮
是pressed。但是分配的内容的的EditText
似乎从来没有被分配到每当一个新值在输入新内容的值的字符串输入。
结果插入新记录只能使用一次。
任何建议,为什么出现这种情况是AP preciated。
公共无效insertRecord(查看additionBut){
的System.out.println(NOW INSIDE插入记录);
。输入= addTextInput.getText()的toString();
addTextInput.getText()清()。
的System.out.println(输入);
如果(purpose.equals(ViewNovel)){
md.addPiece(输入0);
}否则如果(purpose.equals(ViewPlay)){
md.addPiece(输入1);
}其他{
//任何其他
} DisplayList中();
}
解决方案
您也可以清除您的EditText以另一种方式,尝试以下方法,
公共无效insertRecord(查看additionBut){
的System.out.println(NOW INSIDE插入记录);
。输入= addTextInput.getText()的toString();
addTextInput.setText()//这里更改
的System.out.println(输入);
如果(purpose.equals(ViewNovel)){
md.addPiece(输入0);
}否则如果(purpose.equals(ViewPlay)){
md.addPiece(输入1);
}其他{
//任何其他
} DisplayList中();
}
The method below is responsible for inserting a new record to a database table and it is called when a button
is pressed. However the String input that is assigned the value of the contents of the EditText
never seems to be assigned to the new contents whenever a new value is typed in.
As a result inserting a new record only works once.
Any suggestions why this happens would be appreciated.
public void insertRecord(View additionBut) {
System.out.println("NOW INSIDE THE INSERT RECORD");
input = addTextInput.getText().toString();
addTextInput.getText().clear();
System.out.println(input);
if (purpose.equals("ViewNovel")) {
md.addPiece(input, "0");
} else if (purpose.equals("ViewPlay")) {
md.addPiece(input, "1");
} else {
// whatever else
}
displayList();
}
解决方案
You can also clear your EditText in another way, Try following way,
public void insertRecord(View additionBut) {
System.out.println("NOW INSIDE THE INSERT RECORD");
input = addTextInput.getText().toString();
addTextInput.setText("") // Change here
System.out.println(input);
if (purpose.equals("ViewNovel")) {
md.addPiece(input, "0");
} else if (purpose.equals("ViewPlay")) {
md.addPiece(input, "1");
} else {
// whatever else
}
displayList();
}
这篇关于安卓的EditText返回值相同的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文