Guest User

CustomAdapter

a guest
Jan 5th, 2015
131
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public class CustomAdapter extends ArrayAdapter<CustomItem> {
  2.    
  3.         private final Context context;
  4.         private final ArrayList<CustomItem> mItemsArrayList;
  5.         private CustomFragment mFragment;
  6.    
  7.    
  8.         public CustomAdapter(Context context, ArrayList<CustomItem> itemsArrayList, CustomFragment fragment) {
  9.    
  10.             super(context, R.layout.watch_list_row, itemsArrayList);
  11.    
  12.             this.context = context;
  13.             this.mItemsArrayList = itemsArrayList;
  14.             this.mFragment = fragment;
  15.         }
  16.    
  17.         @Override
  18.         public View getView(int position, View convertView, ViewGroup parent) {
  19.             final int pos = position;
  20.             LayoutInflater inflater = (LayoutInflater) context
  21.                     .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  22.    
  23.             final View rowView = inflater.inflate(R.layout.watch_list_row, parent, false);
  24.    
  25.             final ImageView popupButton = (ImageView) rowView.findViewById(R.id.imgPopUp);
  26.             popupButton.setOnClickListener(new View.OnClickListener() {
  27.    
  28.                 @Override
  29.                 public void onClick(View v) {
  30.    
  31.                     PopupMenu popup = new PopupMenu(context, popupButton);
  32.                     //Inflating the Popup using xml file
  33.                     popup.getMenuInflater().inflate(R.menu.popup_menu, popup.getMenu());
  34.    
  35.                     popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
  36.                         public boolean onMenuItemClick(MenuItem item) {
  37.                             int i = item.getItemId();
  38.                             return onMenuItemClick(item);
  39.                         }
  40.                     });
  41.                     popup.show();//showing popup menu
  42.                 }
  43.             });
  44.             return rowView;
  45.         }
  46.     }
RAW Paste Data