import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
/**
* Class which shows how to validate user input with regular expression
*
* @author FaYnaSoft Labs
*/
public class Main extends Activity {
private EditText editText;
private Button button;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
editText = (EditText) findViewById(R.id.textId);
editText.setText("EditText element");
button = (Button) findViewById(R.id.btnId);
button.setText("Check");
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(checkString(editText.getText().toString())) {
editText.setText("Corect");
}
}
});
}
/**
* This method checks if String is correct
* @param s - String which need to check
* @return value of matching
*/
private boolean checkString(String s) {
return s.matches("\\w*[.](java|cpp|class)");
}
}