Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would implement view classes (in <a href="http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller" rel="nofollow">Model-View-Controller</a> notation) that represent the necessary controls and would use <a href="http://docs.oracle.com/javase/tutorial/java/IandI/polymorphism.html" rel="nofollow">polymorphism</a> to avoid these if statements.</p> <p><strong>UPDATE:</strong></p> <p>As I understand there is shown an input validation mechanism. I would do the following.</p> <p>My explanation could be more general than it is expected for your particular task. But I think it will help you in future. And please note I am not too proficient with Android API, so you may need to adjuct my references to some Android API classes, for instance a class, that represents a field.</p> <p>So, the first step. Declare the field prototype:</p> <pre><code>abstract FieldPrototype extends AndroidFieldClass { /** * Checks field contents and returns true if field is ok, otherwise shows popup validation message and returns false. * @return see method description. */ public abstract boolean checkField(); } class Et1Field extends FieldPrototype { private String value; public Et1Field() { super(); // your initialization code here } public boolean checkField() { if (value == null || "".equals(value)) { // show validation message specific for Et1Field class instance. return false; } return true; } } // do the same steps for Et2Field .. Et13Field if those fields are different, // and implement specific validation functionality for every kind of a field. </code></pre> <p>In your screen class keep an array of all fields displayed on this screen. On save event in your screen, send <code>save</code> event to all field instances. Every field will invoke it's own checkField() method and validate it's own contents, without showing particular field implementation outside. And if a field validation failed you just stop and let a user to correct a field contents.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload