public void showFavouritePopup(final int eventId) { LayoutInflater inflater = getLayoutInflater(); LinearLayout popup = (LinearLayout) inflater.inflate(R.layout.category_popup, null); Button btnCompany = (Button) popup.findViewById(R.id.btnCompany); Button btnEvent = (Button) popup.findViewById(R.id.btnEvent); EventsBusinessLayer ebl = new EventsBusinessLayer(); final UserAccountBusinessLayer uabl = new UserAccountBusinessLayer(); TextView dialogText = (TextView) popup.findViewById(R.id.add_favorite_text); if (ebl.isEventAttendedByUser(eventId, AppConstants.USER_ID) && uabl.isBusinessIsInUserFavorites(businessId, AppConstants.USER_ID)) { dialogText.setText(R.string.all_added_to_favorite); } else { dialogText.setText(R.string.add_to_favorite); } if (ebl.isEventAttendedByUser(eventId, AppConstants.USER_ID)) { btnEvent.setVisibility(View.GONE); } if (uabl.isBusinessIsInUserFavorites(businessId, AppConstants.USER_ID)) { btnCompany.setVisibility(View.GONE); } btnCompany.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { int duration = Toast.LENGTH_SHORT; CharSequence text = ""; int status = Ga2ooJsonParsers.getInstance().addBusinessToUser(AppConstants.USER_ID, businessId); if (status > 0) { text = getResources().getString(R.string.company_added_successfully); Business tmpBusiness = new Business(); tmpBusiness.businessid = businessId; tmpBusiness.businessname = " "; tmpBusiness.useraddedbusinessid = 0; tmpBusiness.date_updated = "0"; uabl.InsertUserBusiness(tmpBusiness); Toast toast = Toast.makeText(context, text, duration); toast.show(); } else if (status == 0) { text = getResources().getString(R.string.compamy_already_in_your_favorite); Toast toast = Toast.makeText(context, text, duration); toast.show(); } else if (status == -1) { DialogUtility.showConnectionErrorDialog(MoreEventsByBusiness.this.getParent()); } customDialog.dismiss(); } }); btnEvent.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { customDialog.dismiss(); int duration = Toast.LENGTH_SHORT; CharSequence text = ""; // Ga2ooParsers objGa2ooParsers=new Ga2ooParsers(); // int status=objGa2ooParsers.addEventToUser(AppConstants.USER_ID,eventId); int status = Ga2ooJsonParsers.getInstance().addEventToUser(AppConstants.USER_ID, eventId); if (status > 0) { text = getResources().getString(R.string.event_successfully_added); eventsBL = new EventsBusinessLayer(); eventsBL.addToAttending(eventId, AppConstants.USER_ID); userActBL.insertUserFavorites(AppConstants.USER_ID, eventId, status); Toast toast = Toast.makeText(context, text, duration); toast.show(); } else if (status == 0) { text = getResources().getString(R.string.event_already_in_palendar); Toast toast = Toast.makeText(context, text, duration); toast.show(); } else if (status == -1) { DialogUtility.showConnectionErrorDialog(MoreEventsByBusiness.this.getParent()); } } }); customDialog = new PopUpDailog(getParent(), popup, 220, LayoutParams.WRAP_CONTENT); customDialog.show(); }