Created
September 3, 2015 19:07
-
-
Save ralphpina/4ce75285c19bb300c1d9 to your computer and use it in GitHub Desktop.
Sample Interview Activity
This file contains 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
public class MainActivity extends AppCompatActivity { | |
private TextView _name; | |
private TextView _address; | |
private TextView _phoneNumber; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
initViews(); | |
Contact contact = DataModel.getContact(); | |
if (contact != null) { | |
setUpContact(contact); | |
} else { | |
new MainActivityLoader().load(); | |
} | |
} | |
private void initViews() { | |
_name = (TextView) findViewById(R.id.name); | |
_address = (TextView) findViewById(R.id.address); | |
_phoneNumber = (TextView) findViewById(R.id.phoneNumber); | |
} | |
public class MainActivityLoader implements AbstractLoader { | |
@Override | |
public Contact doInBackground() { | |
Contact contact = loadNetworkCotactSync(); | |
setUpContact(contact); | |
return contact; | |
} | |
@Override | |
public void doInForeground(Contact contact) { | |
DataModel.persistContact(contact); | |
} | |
} | |
private void setUpContact(Contact contact) { | |
_name.setText(contact.getName()); | |
_address.setText(contact.getAddress()); | |
_phoneNumber.setText(contact.getPhoneNumber()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment