Advertisement
Guest User

horoscoop_Activity

a guest
Mar 27th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. public class HoroscoopActivity extends ListActivity {
  2.  
  3. private HoroscoopAdapter hAdapter;
  4. @Override
  5. protected void onCreate(Bundle savedInstanceState) {
  6. super.onCreate(savedInstanceState);
  7.  
  8. hAdapter = new HoroscoopAdapter();
  9. setListAdapter(hAdapter);
  10. }
  11.  
  12.  
  13. @Override
  14. public boolean onCreateOptionsMenu(Menu menu) {
  15. // Inflate the menu; this adds items to the action bar if it is present.
  16. getMenuInflater().inflate(R.menu.menu_horoscoop, menu);
  17. return true;
  18. }
  19.  
  20. @Override
  21. public boolean onOptionsItemSelected(MenuItem item) {
  22. // Handle action bar item clicks here. The action bar will
  23. // automatically handle clicks on the Home/Up button, so long
  24. // as you specify a parent activity in AndroidManifest.xml.
  25. int id = item.getItemId();
  26.  
  27. //noinspection SimplifiableIfStatement
  28. if (id == R.id.action_settings) {
  29. return true;
  30. }
  31.  
  32. return super.onOptionsItemSelected(item);
  33. }
  34.  
  35. class HoroscoopAdapter extends ArrayAdapter<Data.Horoscoop> {
  36. public HoroscoopAdapter() {
  37. super(HoroscoopActivity.this, R.layout.row_horoscoop,
  38. R.id.tvHoroscoopNaam, Data.Horoscoop.values());
  39. }
  40.  
  41. @Override
  42. public View getView(int position, View convertView, ViewGroup parent) {
  43. View row = super.getView(position, convertView, parent);
  44.  
  45. Data.Horoscoop horoscoop = Data.Horoscoop.values()[position];
  46.  
  47. TextView tvHoroscoopNaam = (TextView) row.findViewById(R.id.tvHoroscoopNaam);
  48. tvHoroscoopNaam.setText(horoscoop.getNaamHoroscoop());
  49.  
  50. ImageView ivHoroscoop = (ImageView)row.findViewById(R.id.ivHoroscoop);
  51. ivHoroscoop.setImageResource(getResourceId(horoscoop));
  52.  
  53. return row;
  54. }
  55.  
  56. private int getResourceId(Data.Horoscoop horoscoop) {
  57. switch (horoscoop) {
  58. case WATERMAN:
  59. return R.drawable.waterman;
  60. case VISSEN:
  61. return R.drawable.vissen;
  62. case RAM:
  63. return R.drawable.ram;
  64. case STIER:
  65. return R.drawable.stier;
  66. case TWEELING:
  67. return R.drawable.tweeling;
  68. case KREEFT:
  69. return R.drawable.kreeft;
  70. case LEEUW:
  71. return R.drawable.leeuw;
  72. case MAAGD:
  73. return R.drawable.maagd;
  74. case WEEGSCHAAL:
  75. return R.drawable.weegschaal;
  76. case SCHORPIOEN:
  77. return R.drawable.schorpioen;
  78. case BOOGSCHUTTER:
  79. return R.drawable.boogschutter;
  80. case STEENBOK:
  81. return R.drawable.steenbok;
  82. default: return 0;
  83. }
  84. }
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement