public void handleMessage(Message message) { String TAG = className + ".handleMessage"; PBLogger.entry(TAG); String json = (String) message.obj; if (message.arg1 == RESULT_OK && json != null) { try { cats = CategoriesListHelper.parseCategoriesFromJson(resources, json); CategoryListActivity.this.loadCatsIntoPreferences(cats); // OK...only now should we proceed to list the categories. CategoryListActivity.this.showCategories(cats); } catch (PBException e) { Toast.makeText( CategoryListActivity.this, resources.getString(R.string.errorTryingToParseCategories), Toast.LENGTH_LONG) .show(); PBLogger.e(TAG, resources.getString(R.string.errorTryingToParseCategories), e); } } else { Toast.makeText( CategoryListActivity.this, resources.getString(R.string.errorTryingToGetCategoriesFromService), Toast.LENGTH_LONG) .show(); PBLogger.e(TAG, resources.getString(R.string.errorTryingToGetCategoriesFromService)); } PBLogger.exit(TAG); }
private void showCategories(ArrayList<OpportunityCategory> cats) { String TAG = className + ".showCategories"; PBLogger.entry(TAG); setContentView(R.layout.activity_category_list); // Grab resources - they will come in handy later. if (resources == null) resources = this.getResources(); // Put all the categories into the list. ListView itemlist = (ListView) findViewById(R.id.listCategory); // attach list click adapter. ArrayAdapter<OpportunityCategory> adapter = new ArrayAdapter<OpportunityCategory>( CategoryListActivity.this, android.R.layout.simple_list_item_1, cats); if (itemlist == null || adapter == null) { PBLogger.e(TAG, "null itemlist or adapter...itemlist = " + itemlist + " adapter " + adapter); } else { itemlist.setAdapter(adapter); itemlist.setSelection(0); itemlist.setOnItemClickListener((OnItemClickListener) CategoryListActivity.this); } // Show overlay - first time only SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CategoryListActivity.this); showOverlay = prefs.getBoolean("showOverlay", true); PBLogger.i(TAG, "onCreate showOverlay =" + showOverlay); if (showOverlay == true) { showCategoriesOverlay(); } PBLogger.exit(TAG); }