我想在点击提交按钮时验证包含数字的编辑文本 但不适用
这是我的代码
alert = new AlertDialog.Builder(Map.this);
alert.setTitle("About");
alert.setMessage("You have to enter a number of Boundaries and Kilometers");
alert.setIcon(R.drawable.tick);
alert.setNegativeButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
}
});
noOfCircles=(EditText)findViewById(R.id.boundary);
Kilometers=(EditText) findViewById(R.id.diameter);
submit.setOnClickListener(new OnClickListener(){
public void onClick(View v){
if(noOfCircles.getText().toString().equalsIgnoreCase("helloworld")||Kilometers.getText().toString().equalsIgnoreCase("helloworld")){
alert.show();
}
}
});
}
答案 0 :(得分:0)
从警告消息中,您似乎正在尝试检查是否已输入两个值。如果是这种情况,请尝试以下代码:
submit.setOnClickListener(new View.OnClickListener(){
public void onClick(View v){
String circles = noOfCircles.getText().toString();
String kilometers = Kilometers.getText().toString();
if(circles.equalsIgnoreCase("") || kilometers.equalsIgnoreCase("")){
alert.setMessage("Please enter both values!");
}
else{
if(circles.equalsIgnoreCase(kilometers)){
alert.setMessage("Values are equal");
//do your own stuff here
}
}
alert.show();
}
});