We can update immediately background color in items cells (on visibile view) by calling invalidateViews() after do the update. Here is the implementation :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | // Set image adapter instance from private variable imageAdapter = new ItemAdapter(this); // Bind Gridview with calendar XML and set the Adapter final GridView gridView = (GridView) findViewById(R.id.calendar); gridView.setAdapter(imageAdapter); Button workout = (Button) findViewById(R.id.top_done_button); workout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Context context = getApplicationContext(); String text = "Yeah! You’re ready workout now!"; Toast toast = Toast.makeText(context, text, Toast.LENGTH_SHORT); toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0); toast.show(); // Set date pickers cells imageAdapter.setDatePicker(today.getDate()); gridView.invalidateViews(); } }); |
invalidateViews() called after we doing update on Gridviews items on setDatePicker() method.
Here is the result (without scrolling to update the views) :
And, after I click the workout button:
Next update:
http://www.yodi.biz/2012/12/22/bodyslap-fitness-and-workout-tracker-android-application-part-3/