Last active
February 25, 2016 15:10
-
-
Save crabbits/bb024cb0ba6e70e02a69 to your computer and use it in GitHub Desktop.
Android form helper (WIP)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
import java.util.Map.Entry; | |
import android.app.Activity; | |
import android.content.Context; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.EditText; | |
import android.widget.TextView; | |
public class DroidForm { | |
private Map<EditText,Boolean> requiredFields; | |
private Iterator<Entry<EditText,Boolean>> iterator; | |
private Context context; | |
public DroidForm(Context context) { | |
this.context = context; | |
this.requiredFields = new HashMap<EditText,Boolean>(); | |
} | |
public void addField(int id, Boolean required) { | |
EditText field = (EditText) ((Activity) context).findViewById(id); | |
this.requiredFields.put(field, required); | |
} | |
public boolean formValid() { | |
iterator = requiredFields.entrySet().iterator(); | |
while(iterator.hasNext()) { | |
Map.Entry<EditText,Boolean> field = (Map.Entry<EditText,Boolean>)iterator.next(); | |
if(field.getValue() == true && field.getKey().getText().toString().isEmpty()) { | |
return false; | |
} | |
} | |
return true; | |
} | |
public String valueOf(int id) { | |
iterator = requiredFields.entrySet().iterator(); | |
View view = ((Activity) context).findViewById(id); | |
while(iterator.hasNext()) { | |
Map.Entry<EditText,Boolean> nextField = (Map.Entry<EditText,Boolean>)iterator.next(); | |
if(nextField.getKey() == view) { | |
return nextField.getKey().getText().toString(); | |
} | |
} | |
return null; | |
} | |
public void displayErrorMessages() { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
check out https://github.com/RbkGh/FormHelper, @ctountzis,this will save you a lot of this headache you are going through