Skip to content

Instantly share code, notes, and snippets.

@miensol
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miensol/52b98f0fcbe89db81441 to your computer and use it in GitHub Desktop.
Save miensol/52b98f0fcbe89db81441 to your computer and use it in GitHub Desktop.
<TextView
android:id="@+id/first_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/first_name_hint"
android:visibility="invisible"
android:theme="@style/Label.Small"/>
<EditText
android:id="@+id/first_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:hint="@string/first_name_hint"
android:inputType="textPersonName"/>
<TextView
android:id="@+id/error"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/register"/>
<Button
android:id="@+id/register"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/register"
android:layout_alignParentBottom="true"/>
interface Action2<T,Throwable> {
void call(T t, Throwable error);
}
interface RegisterApi {
class RegistrationModel {
String firstName;
}
void register(RegistrationModel data, Action2<RegistrationModel, Throwable> result);
}
public class RegisterActivityClassic extends Activity {
RegisterApi registerApi; // inject or create remote api
RegisterApi.RegistrationModel data = new RegisterApi.RegistrationModel();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register_classic);
final EditText firstName = (EditText) findViewById(R.id.first_name);
final TextView firstNameLabel = (TextView) findViewById(R.id.first_name_label);
firstName.addTextChangedListener(new TextWatcherBase() {
@Override
public void afterTextChanged(Editable s) {
data.firstName = s.toString();
firstNameLabel.setVisibility(TextUtils.isEmpty(s) ? View.INVISIBLE : View.VISIBLE);
}
});
findViewById(R.id.register).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
registerApi.register(data, new Action2<RegisterApi.RegistrationModel, Throwable>() {
@Override
public void call(RegisterApi.RegistrationModel registrationModel, Throwable error) {
TextView text = (TextView) findViewById(R.id.error);
text.setText(error.getLocalizedMessage());
}
});
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment