Guest User

Untitled

a guest
Aug 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. public class Breakfast extends Activity{
  2.  
  3.  
  4. ListView mylistview;
  5.  
  6. ArrayAdapter<String> listAdapter;
  7.  
  8. TextView display;
  9.  
  10.  
  11.  
  12. public int counter = 0;
  13.  
  14.  
  15.  
  16. public void onCreate(Bundle savedInstanceState) {
  17.  
  18. super.onCreate(savedInstanceState);
  19.  
  20. setContentView(R.layout.breakfast);
  21.  
  22.  
  23.  
  24. display = (TextView) findViewById(R.id.tvDisplay);
  25.  
  26. mylistview = (ListView)findViewById(R.id.listView1);
  27.  
  28.  
  29.  
  30. final int[] caloriesBreakfast = getResources().getIntArray(R.array.caloriesBreakfas_array);
  31.  
  32.  
  33.  
  34. final String[] mealsBreakfast = getResources().getStringArray(R.array.mealsBreakfast_array);
  35.  
  36.  
  37.  
  38. listAdapter = new ArrayAdapter<String>(this, R.layout.listitem, mealsBreakfast);
  39.  
  40.  
  41.  
  42. mylistview.setAdapter(listAdapter);
  43.  
  44.  
  45.  
  46. //For ListItem Click
  47.  
  48. mylistview.setOnItemClickListener(new OnItemClickListener() {
  49.  
  50.  
  51.  
  52. public void onItemClick(AdapterView<?> arg0, View arg1, int position,
  53.  
  54. long arg3) {
  55.  
  56.  
  57. int calories = caloriesBreakfast[position];
  58.  
  59. Intent intent= getIntent();
  60. int counter = intent.getIntExtra("key", 0);
  61. // msg += ", Added at Third"; HOW TO ADD CURRENT RESULT HERE?
  62.  
  63. counter += calories;
  64. display.setText("Result: " + counter);
  65.  
  66.  
  67. intent.putExtra("currentresult", counter);
  68. setResult(RESULT_OK, intent);
  69. finish();
  70.  
  71. }
Add Comment
Please, Sign In to add comment