Android Open Source - ExpertAndroid Main Activity

From Project

Back to project page ExpertAndroid.


The source code is released under:

MIT License

If you think the Android project ExpertAndroid listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.iuriio.demos.expertandroid.ch6forms;
//www .ja  va2s .  c  o  m
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.os.Build;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class MainActivity extends FormActivity implements View.OnClickListener {
    private static final String TAG = "MainActivity";

    private EditText userid;
    private EditText password1;
    private EditText password2;
    private EditText email;

    public MainActivity() {

    protected void onCreate(Bundle savedInstanceState) {

        final Button signUp = (Button) this.findViewById(;

    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(, menu);
        return true;

    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        switch (item.getItemId()) {
                return true;
        return super.onOptionsItemSelected(item);

    protected void initializeFormFields() {
        this.reportBack("Form initialized");

        this.userid = (EditText) this.findViewById(;
        this.password1 = (EditText) this.findViewById(;
        this.password2 = (EditText) this.findViewById(; = (EditText) this.findViewById(;

        this.addValidator(new Field(this.userid));
        this.addValidator(new Field(this.password1));
        this.addValidator(new Field(this.password2));
        this.addValidator(new Field(;
        this.addValidator(new PasswordFieldRule(this.password1, this.password2));

     * Called when a view has been clicked.
     * @param v The view that was clicked.
    public void onClick(View v) {
        switch (v.getId()) {

                if (!this.validateForm()) {
                    this.reportTransient("Make sure all fields have valid values");

                final String userid = this.getUserId();
                final String password = this.getPassword1();
                final String email = this.getUserEmail();
                this.signup(userid, email, password);


    private void signup(String userid, String email, String password) {

    private String getUserId() {
        return this.getStringValue(;

    private String getUserEmail() {
        return this.getStringValue(;

    private String getPassword1() {
        return this.getStringValue(;

    private String getStringValue(int controlId) {
        final TextView textView = (TextView) this.findViewById(controlId);
        if (textView == null) {
            throw new RuntimeException("Sorry cant find control by id");

        return textView.getText().toString();

Java Source Code List