PullToRefreshListView長(zhǎng)按收藏(奶瓶)

1,上下文對(duì)象是 Activity 是this;
fragment 上下文對(duì)象是你定義的 rootView;
rootView = inflater.inflate(R.layout.layout_listeview, null);
2,獲取當(dāng)前Int值的位置,使用長(zhǎng)按里的 position;

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

PullToRefreshListView的長(zhǎng)按

     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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容