SHARE
TWEET

Untitled

a guest Mar 26th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3.     DateViewModel model;
  4.     private TextView dateTextView;
  5.  
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         setContentView(R.layout.activity_main);
  10.  
  11.         model = ViewModelProviders.of(this).get(DateViewModel.class);
  12.         dateTextView = findViewById(R.id.dateTextView);
  13.  
  14.         Toast.makeText(this, model.getCurrentDate().getValue(), Toast.LENGTH_LONG).show();
  15.  
  16.         final Observer<String> dateObserver = new Observer<String>() {
  17.             @Override
  18.             public void onChanged(@Nullable String date) {
  19.                 dateTextView.setText(date);
  20.             }
  21.         };
  22.  
  23.         model.getCurrentDate().observe(this, dateObserver);
  24.     }
  25.  
  26.     public void onButtonClicked(View view) {
  27.         model.getCurrentDate().setValue(new Date().toString());
  28.     }
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top