PullToRefreshListView长按收藏(奶瓶)

1,上下文对象是 Activity 是this;
fragment 上下文对象是你定义的 rootView;
rootView = inflater.inflate(R.layout.layout_listeview, null);
2,获取当前Int值的位置,使用长按里的 position;

prfListView.getRefreshableView().setOnItemLongClickListener(new 用的是

PullToRefreshListView的长按

     prfListView.getRefreshableView().setOnItemLongClickListener(new                  
      AdapterView.OnItemLongClickListener() {
         @Override
          public boolean onItemLongClick(AdapterView parent, View view, final int           
        position, long id) {
            new AlertDialog.Builder(rootView.getContext())
                    .setTitle("收藏")
                    .setMessage("是否收藏?")
                    .setPositiveButton("收藏", new  DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            Account account =  
      BmobUser.getCurrentUser(BaseApplication.getInstance(),Account.class);
                            if(account != null){
                                CollectionBean collectionBean = new CollectionBean();
                                                   
      collectionBean.setPicUrl(data.get(position).getThumbnail_pic_s());
                                collectionBean.setuId(account.getObjectId());
                                collectionBean.setUrl(data.get(position).getUrl());
                                collectionBean.setTitle(data.get(position).getTitle());
                                collectionBean.setType(Constant.COLLECTION_TYPE_NEWS);
                                collectionBean.save(prfListView.getContext(), new SaveListener() 
   {
                                    @Override
                                    public void onSuccess() {
                                        Toast.makeText(rootView.getContext(),"收藏成
     功",Toast.LENGTH_SHORT).show();
                                    }
                                    @Override
                                    public void onFailure(int i, String s) {
                                        Toast.makeText(rootView.getContext(),"收藏失
   败",Toast.LENGTH_SHORT).show();
                                    }
                                });
                            }
                        }
                    })
                    .setNegativeButton("取消",null)
                    .create()
                    .show();
            return false;
        }
 });

GitHub:https://github.com/zlw1347822194/MilkSeven

你可能感兴趣的:(PullToRefreshListView长按收藏(奶瓶))