Advertisement
Guest User

horoscoopactivity

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