Created
October 2, 2017 20:56
-
-
Save PierceZ/8d02740af2ae1c6401a06cb8269c99f2 to your computer and use it in GitHub Desktop.
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 ZooListViewModel mViewModel; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
RecyclerView recyclerView = findViewById(R.id.activity_main_recyclerview); | |
recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false)); | |
ZooAdapter adapter = new ZooAdapter(); | |
adapter.setOnClickListener((view, position) -> { | |
Intent zooIntent = new Intent(MainActivity.this, ZooActivity.class); | |
zooIntent.putExtra(ZooActivity.EXTRA_ZOO_ID, adapter.getItemId(position)); | |
startActivity(zooIntent); | |
}); | |
recyclerView.setAdapter(adapter); | |
mViewModel = ViewModelProviders.of(this).get(ZooListViewModel.class); | |
mViewModel.getZoos().observe(this, (adapter::update)); | |
findViewById(R.id.activity_main_fab).setOnClickListener(v -> { | |
DialogFragment zooFragment = ZooFragment.newInstance(); | |
zooFragment.show(getSupportFragmentManager(), ZooFragment.class.getName()); | |
}); | |
} | |
@Override | |
protected void onResume() { | |
super.onResume(); | |
mViewModel.refreshZoos(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment