Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HoroscoopActivity extends ListActivity {
- private HoroscoopAdapter hAdapter;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- hAdapter = new HoroscoopAdapter();
- setListAdapter(hAdapter);
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_horoscoop, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- class HoroscoopAdapter extends ArrayAdapter<Data.Horoscoop> {
- public HoroscoopAdapter() {
- super(HoroscoopActivity.this, R.layout.row_horoscoop,
- R.id.tvHoroscoopNaam, Data.Horoscoop.values());
- }
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- View row = super.getView(position, convertView, parent);
- Data.Horoscoop horoscoop = Data.Horoscoop.values()[position];
- TextView tvHoroscoopNaam = (TextView) row.findViewById(R.id.tvHoroscoopNaam);
- tvHoroscoopNaam.setText(horoscoop.getNaamHoroscoop());
- ImageView ivHoroscoop = (ImageView)row.findViewById(R.id.ivHoroscoop);
- ivHoroscoop.setImageResource(getResourceId(horoscoop));
- return row;
- }
- private int getResourceId(Data.Horoscoop horoscoop) {
- switch (horoscoop) {
- case WATERMAN:
- return R.drawable.waterman;
- case VISSEN:
- return R.drawable.vissen;
- case RAM:
- return R.drawable.ram;
- case STIER:
- return R.drawable.stier;
- case TWEELING:
- return R.drawable.tweeling;
- case KREEFT:
- return R.drawable.kreeft;
- case LEEUW:
- return R.drawable.leeuw;
- case MAAGD:
- return R.drawable.maagd;
- case WEEGSCHAAL:
- return R.drawable.weegschaal;
- case SCHORPIOEN:
- return R.drawable.schorpioen;
- case BOOGSCHUTTER:
- return R.drawable.boogschutter;
- case STEENBOK:
- return R.drawable.steenbok;
- default: return 0;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement