1,上下文對象是 Activity 是this硕盹;
fragment 上下文對象是你定義的 rootView;
rootView = inflater.inflate(R.layout.layout_listeview, null);
2蛤奢,獲取當(dāng)前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;
}
});