第一步需要一個顯示收藏的Adapter,代碼很簡單我就不貼了可以參考:
http://www.lxweimin.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();
}
});
}
}
}
代碼只供學習,謝謝,有什么不足與錯誤,請大牛指點。