I am working on an Android application.
The application has a series of forms and I want to confirm that the user filled out those forms before he moves on to the next set of forms. What would be the best way to do that?
public void goOne()
{
setContentView(R.layout.main);
next = (Button) findViewById(R.id.next);
logo = (Button) findViewById(R.id.logo);
cityText = (EditText)findViewById(R.id.city);
about = (Button) findViewById(R.id.aboutus);
about.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
goAboutUs();
}
});
logo.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
goOne();
}
});
next.setOnClickListener(new View.OnClickListener() {
public void onClick(View v)
{
city = (String)cityText.getText().toString();
if(stateLoc.equalsIgnoreCase("international"))
{
location = "";
isInternational = 1;
}else
{
location = city;
}
if(cityText.getText().equals("") && stateLoc.equalsIgnoreCase("U.S.A"))
{
new AlertDialog.Builder(Tents.this)
.setTitle("Error")
.setMessage("Enter ZIP Code, or choice International ")
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
goOne();
}
}).show();
}else{
goTwo();
}
}
});
that is my code. And I am trying to validate the cityText textbox. If it doesnt have anything in it and the stateLoc is set to U.S.A then pop up alert if not then goTwo()
If the forms are normal text views, you could use the following code:
myTextView.getText().trim().isEmpty()will return whether the textview is empty or not