So I have two EditText
fields. One is for a category and the other one to place a link in it. If you click on the button "weiter" there is a control if the EditText
are empty. In the next step I want to make sure that in the EditText
link is an real link and not just e.g. only a word. So I want to check if it contains www.
and now the problem is how can I make a break if it doesn't contain it?
That the new Intent
starts because I set it in the next if-else
that's clear.
So how can I make it better?
Here's my code thank you all:
((Button) findViewById(R.id.weiter)).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity2.this, MainActivity8.class);
EditText et1 = (EditText) findViewById(R.id.editText2);
String Link1 = et1.getText().toString();
EditText et = (EditText) findViewById(editText1);
String Kategorie1 = et.getText().toString();
if (Link1.contains("www.")) {
} else {
et1.setError("Link ist nicht gültig");
}
if (Link1.matches("") || Kategorie1.matches("")) {
et.setHintTextColor(RED);
et1.setHintTextColor(RED);
} else {
i.putExtra("ersteActivityKategorie", Kategorie1);
i.putExtra("ersteActivityLink", Link1);
startActivity(i);
}
}
});