<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## (一).前言: 項目開發中對于列表(listview)和表格(girdview)中的數據顯示,我們就需要寫自定義的Adapter。所以一般一個項目下來少得十幾個Adapter,多的二十幾個甚至更多。但是Adapter的處理一般就是傳入數據,view模板,getView,之類的在加入一些控制顯示之類的代碼。雖然寫起來難度不大,但是很多類似的代碼經常需要狂寫,簡直會有想吐的趕腳吧~。今天為大家介紹一款快速Adapter的框架,只需要創建QuickAdapter,傳入布局,數據,然后綁定控件以及顯示的數據即可。這樣一講是不是趕腳非常方便了,OK我們趕緊行動吧~。 Base-Adapter-Helper[(Github地址)](https://github.com/JoanZapata/base-adapter-helper) FastDev4Android框架項目地址:[https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android) ## (二).基本介紹: 2.1:BaseAdapterHelper是BaseAdapter?ViewHolder模板的抽象,讓我們更快的寫出Adapter來綁定數據顯示。官網給出的使用實例和實現效果如下: ![](https://box.kancloud.cn/2016-01-18_569c8eb728064.jpg) 下載該項目下來,整個項目一共四個類文件: * BaseAdapterHelper?可以使得BaseAdapter的getView()方法更加簡單的使用。擺脫ViewHolder模板的寫法 * QuickAdapter??該類可以讓我們自定義的BaseAdapter類的代碼大量的縮減,讓我們把精力集中在業務實現上面。我們只需要做的是綁定控件view和數據model即可。 * EnhancedQuickAdapter??增強的QuickAdapter,主要是用于綁定控件view和數據model * BaseQuickAdapter??QuickAdapter的高層類封裝,實現BaseAdapter中抽象方法,同時對于data數據的操作以及其他操作 2.2.AndroidStudio引入Base-Adapter-Helper庫,一種方式最簡單了直接使用以下方式依賴: ~~~ compile'com.joanzapata.android:base-adapter-helper:1.1.11' ~~~ 我這邊采用的是第二種方式:因為該庫只有四個類,所以我就把這個類直接復制進入去了,如下: ![](https://box.kancloud.cn/2016-01-18_569c8eb7505dd.jpg) 不過直接這樣還行,因為該項目中setImageUrl()方法中圖片異步加載采用的是Picasso框架,所以要么你 修改該框架,要么你就可以以下方式引入該框架: ~~~ compile 'com.squareup.picasso:picasso:2.5.2' ~~~ ???????? 2.3.BaseAdapterHelper中的方法介紹: * 對于任何TextView:setText()調用setText(String) * 對于任何View:setAlpha()調用setAlpha(float) * 對于任何View:setVisiable()調用setVisibility(int) * 對于任何TextView:linkify()調用Linkify.addLinks(view,ALL) * 對于任何TextView:setTypeface()調用setTypeface(Typeface) * 對于任何ProgressBar:setProgress()調用setProgress(int) * 對于任何ProgressBar:setMax()調用setMax(int) * 對于任何RatingBar:setRating()調用setRating(int) * 對于任何ImageView:setImageResource()調用setImageResource(int) * 對于任何ImageView:setImageDrawable()調用setImageDrawable(Drawable) * 對于任何ImageVIew:setImageBitmap()調用setImageBitmap(bitmap) * 使用setImageUrl()會使用Picasso框架來進行下載圖片然后現在ImageView中 * 使用seImageBuilder()會使用Picasso的圖片請求構建器 * setOnClickListener() * setOnTouchListener() * setOnLongClickListener() * setTag() * setChecked() * setAdapter() 2.4.我們可以使用showIndeterminateProgress(boolean)可以控制列表底下顯示進度。如下: ![](https://box.kancloud.cn/2016-01-18_569c8eb763f4a.jpg) ## (三).使用實例: 有了以上對于框架的基本介紹和引入之后,現在我們可以來具體實現一個例子了,其實用法很簡單: * 準備數據(和以往一樣) * 創建適配器(創建適配器并且綁定數據和相關布局控件,model即可)--這邊就不需要重寫一個自定義的適配器了。 * Listview綁定適配器(和以往一樣) 3.1.準備數據:ModuleBean和DataUtil ~~~ packagecom.chinaztt.fda.entity; /** *當前類注釋:列表數據測試數據實體類 *項目名:FastDev4Android *包名:com.chinaztt.fda.entity *作者:江清清 on 15/11/8 17:56 *郵箱:jiangqqlmj@163.com *QQ: 781931404 * 公司:江蘇中天科技軟件技術有限公司 */ publicclass ModuleBean { private String modulename; private String imgurl; private String description; public ModuleBean() { } public ModuleBean(String modulename, Stringimgurl, String description) { this.modulename = modulename; this.imgurl = imgurl; this.description = description; } public String getModulename() { return modulename; } public void setModulename(Stringmodulename) { this.modulename = modulename; } public String getImgurl() { return imgurl; } public void setImgurl(String imgurl) { this.imgurl = imgurl; } public String getDescription() { return description; } public void setDescription(Stringdescription) { this.description = description; } @Override public String toString() { return "ModuleBean{" + "modulename='" +modulename + '\'' + ", imgurl='" + imgurl+ '\'' + ", description='" +description + '\'' + '}'; } } ~~~ ~~~ packagecom.chinaztt.fda.test; importcom.chinaztt.fda.entity.ModuleBean; importjava.util.ArrayList; importjava.util.List; /** *當前類注釋: *項目名:FastDev4Android *包名:com.chinaztt.fda.test *作者:江清清 on 15/11/8 17:53 *郵箱:jiangqqlmj@163.com *QQ: 781931404 * 公司:江蘇中天科技軟件技術有限公司 */ publicclass DataUtils { /** * 進行構造相關數據 * @return */ public static List<ModuleBean>getAdapterData(){ List<ModuleBean> moduleBeans=newArrayList<ModuleBean>(); ModuleBean moduleBean=new ModuleBean(); moduleBean.setModulename("完美“價”給你"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150325/20150325083110_0898.jpg"); moduleBean.setDescription("標題1的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("探路者,旅行記"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150325/20150325083214_8280.jpg"); moduleBean.setDescription("標題2的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("進口商品,徹底放價"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150328/20150328105404_2392.jpg"); moduleBean.setDescription("標題3的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("鮮果季"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150325/20150325083611_0644.jpg"); moduleBean.setDescription("標題4的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("盼盼 法式小面包"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150312/20150312100454_8837.jpg"); moduleBean.setDescription("標題5的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("雀巢 脆脆鯊 威化 480g/盒"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150312/20150312100617_0693.jpg"); moduleBean.setDescription("標題6的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("主題館1"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150129/20150129163540_6179.jpg"); moduleBean.setDescription("標題7的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("主題館2"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150129/20150129163615_1774.jpg"); moduleBean.setDescription("標題8的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("主題館3"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150129/20150129163635_1130.jpg"); moduleBean.setDescription("標題9的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("主題館4"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150129/20150129163840_0270.jpg"); moduleBean.setDescription("標題10的簡要說明"); moduleBeans.add(moduleBean); moduleBean=new ModuleBean(); moduleBean.setModulename("主題館5"); moduleBean.setImgurl("http://interface.zttmall.com/Images/upload/image/20150129/20150129163849_4099.jpg"); moduleBean.setDescription("標題11的簡要說明"); moduleBeans.add(moduleBean); return moduleBeans; } } ~~~ 3.2.創建適配器(綁定數據,控件相關)和綁定適配器 ~~~ packagecom.chinaztt.fda.test; importandroid.os.Bundle; importandroid.widget.ListView; importcom.chinaztt.fda.adapter.base.BaseAdapterHelper; importcom.chinaztt.fda.adapter.base.QuickAdapter; importcom.chinaztt.fda.entity.ModuleBean; importcom.chinaztt.fda.ui.R; importcom.chinaztt.fda.ui.base.BaseActivity; importorg.androidannotations.annotations.AfterViews; importorg.androidannotations.annotations.EActivity; importorg.androidannotations.annotations.ViewById; importjava.util.List; /** *當前類注釋:baseAdapterhelper 使用實例 *項目名:FastDev4Android *包名:com.chinaztt.fda.test *作者:江清清 on 15/11/8 17:39 *郵箱:jiangqqlmj@163.com *QQ: 781931404 * 公司:江蘇中天科技軟件技術有限公司 */ @EActivity(R.layout.base_adapter_test_layout) publicclass BaseAdapterTestActivity extends BaseActivity { @ViewById ListView lv_base_adapter; private QuickAdapter<ModuleBean>mAdapter; private List<ModuleBean> moduleBeans; @Override protected void onCreate(BundlesavedInstanceState) { super.onCreate(savedInstanceState); } @AfterViews public void bindLvData(){ moduleBeans=DataUtils.getAdapterData(); if(mAdapter==null) { mAdapter = newQuickAdapter<ModuleBean>(this, R.layout.lv_item_base_layout,moduleBeans){ @Override protected voidconvert(BaseAdapterHelper helper, ModuleBean item) { mAdapter.showIndeterminateProgress(true); helper.setText(R.id.text_lv_item_title, item.getModulename()) .setText(R.id.text_lv_item_description, item.getDescription()) .setImageUrl(R.id.img_lv_item, item.getImgurl()); } }; lv_base_adapter.setAdapter(mAdapter); } } } ~~~ 3.3.運行效果如下 ![](https://box.kancloud.cn/2016-01-18_569c8eb78a076.jpg) 好了到此Base-Adapter-Helper的基本介紹和基本使用已經講完了,相信大家已經會初步使用了,下一 篇我們對于源代碼的實現做一個分析和擴展進階使用做講解。具體全部代碼已經上傳到FastDev4Android項目中了。同時歡迎大家去Github站點進行clone或者下載瀏覽: [https://github.com/jiangqqlmj/FastDev4Android](https://github.com/jiangqqlmj/FastDev4Android)?同時歡迎大家star和fork整個開源快速開發框架項目~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看