利用ListView實(shí)現(xiàn)顯示收藏(奶瓶)

第一步需要一個(gè)顯示收藏的Adapter,代碼很簡單我就不貼了可以參考:
http://www.itdecent.cn/p/bc6eb6c485a1
這里的長按收藏。

public class CollectionActivity extends AppCompatActivity {

@BindView(R.id.prf_listView)   //這里用到了注解(ButterKnife)
PullToRefreshListView prfListView;
private View loadFailed;    //聲明并初始化數(shù)據(jù)

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() {
    //設(shè)置列表刷新加載
    prfListView.setMode(PullToRefreshBase.Mode.BOTH);
    colldap = new CollectionAdapter(data);
    //綁定適配器
    prfListView.setAdapter(colldap);
}

@Override
protected void onResume() {
    super.onResume();
    BmobQuerys();
}

//重要代碼(這里用到了Bmob數(shù)據(jù)庫)
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();
            }
        });
    }


}

}
代碼只供學(xué)習(xí),謝謝,有什么不足與錯誤,請大牛指點(diǎn)。

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

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

  • Android 自定義View的各種姿勢1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,094評論 25 709
  • 1. Java基礎(chǔ)部分 基礎(chǔ)部分的順序:基本語法,類相關(guān)的語法,內(nèi)部類的語法,繼承相關(guān)的語法,異常的語法,線程的語...
    子非魚_t_閱讀 34,734評論 18 399
  • 隨性所欲閱讀 757評論 2 1
  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,578評論 19 139
  • 八點(diǎn)多醒來,躺著看小說,餓了吃塊夾心餅干喝點(diǎn)水。一直看到中午兩點(diǎn)多起床,吃了份16元的回鍋肉蓋飯,還是川菜粵菜又便...
    環(huán)華小蝸牛閱讀 343評論 0 1

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