第一步需要一个显示收藏的Adapter,代码很简单我就不贴了可以参考:
http://www.jianshu.com/p/bc6eb6c485a1
这里的长按收藏。
public class CollectionActivity extends AppCompatActivity {
@BindView(R.id.prf_listView) //这里用到了注解(ButterKnife)
PullToRefreshListView prfListView;
private View loadFailed; //声明并初始化数据
private List<CollectionBean> data = new ArrayList<>(); //声明适配器
private CollectionAdapter colldap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_collection);
ButterKnife.bind(this);
initViews();
BmobQuerys();
}
private void initViews() {
//设置列表刷新加载
prfListView.setMode(PullToRefreshBase.Mode.BOTH);
colldap = new CollectionAdapter(data);
//绑定适配器
prfListView.setAdapter(colldap);
}
@Override
protected void onResume() {
super.onResume();
BmobQuerys();
}
//重要代码(这里用到了Bmob数据库)
private void BmobQuerys() {
BmobQuery<CollectionBean> query = new BmobQuery<CollectionBean>();
Account account = BmobUser.getCurrentUser(BaseApplication.getInstance(), Account.class);
if(account == null){
Intent intent = new Intent(this,LoginActivity.class);
startActivity(intent);
}else {
query.addWhereEqualTo("uId", account.getObjectId());
query.setLimit(6);
query.findObjects(this, new FindListener<CollectionBean>() {
@Override
public void onSuccess(List<CollectionBean> list) {
// TODO Auto-generated method stub
if(prfListView != null){
if(prfListView.isRefreshing()){
prfListView.setRefreshing(false);
}
}
colldap.setNewData(list);
}
@Override
public void onError(int code, String msg) {
// TODO Auto-generated method stub
Toast.makeText(CollectionActivity.this, "查询失败", Toast.LENGTH_SHORT).show();
}
});
}
}
}
代码只供学习,谢谢,有什么不足与错误,请大牛指点。