2.Activity啟動模式+Intent+AsylncTask+ListView

一.Activity的啟動模式? 兩種方式四種模式

(1)在清單文件中,標簽中配置android:launchMode=""屬性

? ? ?四個屬性值:

? ? ?<1>standard:

? ? ? ? ? ? ? ? ? ? ? ? ? ? 默認的? 可以實例化多次,每次啟動都會創(chuàng)建一個新的實例

? ? ?<2>singleTop:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?可以實例化多次,當其在棧頂時,只能創(chuàng)建一個實例

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?當棧頂存在要啟動的Activity實例時,系統(tǒng)會調(diào)用onNewIntent()方法

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?把Intent對象傳遞給已經(jīng)存在的Activity實例,從而重用棧頂?shù)腁ctivity

? ? ? <3>singleTask:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 棧內(nèi)部只能有一個Activity實例,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 解釋一:當?shù)诙螁釉揂ctivity時,系統(tǒng)會從上到下依次尋找該Activity已有的實例,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 找到會移除它之上的所有Activity實例,并重用該Activity實例

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 解釋二:當棧中存在要啟動的Activity實例時,系統(tǒng)會調(diào)用onNewIntent() 方法

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 把Intent對象傳遞給已經(jīng)存在的Activity實例,從而重用該Activity實例

? ? ? ?<4>singleInstance:

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 系統(tǒng)會單獨分配一個任務(wù)棧,并把它的實例放到棧底,不和別的Activity共享一個棧

(2)在Activity類中通過Intent對象設(shè)置啟動模式,優(yōu)先級高于上面的方式

? ? ? ? Intent intent = new Intent();

? ? ? ? intent.setFlags(Intent.參數(shù));

參數(shù):

? ? ? ? ? 默認? ? ? ? ? ? ? ? ? ? ? 等同于standard

? ? ? ? ? FLAG_ACTIVITY_SINGLE_TOP? 等同于singleTop

? ? ? ? ? FLAG_ACTIVITY_CLEAR_TOP? 等同于singleTask

? ? ? ? ? FLAG_ACTIVITY_NEW_TASK? ? 等同于singleInstance

? ? ? ? ? 如果是代碼中設(shè)置啟動模式:NEW_TASK,則必須在清單文件中加上下面屬性

? ? ? ? ? android:taskAffinity="com.other"

? ? ? ? ? android:allowTaskReparenting="true"

? ? ? ? ? 否則不起作用

二.Intent七大屬性

(1)Intent的作用

? ? ? 包裝android的組件

? ? ? 啟動Activity ,啟動Service,發(fā)送廣播

? ? ?組件之間的傳值

(2)顯示意圖------setClass()

? ? ? ? ? ? ? ? ? ? ?------setComponent();

明確指定要跳轉(zhuǎn)到哪個Activity(通常用于啟動應(yīng)用內(nèi)部的Activity)

寫法一: Intent intent = new Intent(MainActivity.this,InfoActivity.class);

寫法二: Intent intent= new Intent();

? ? ? ? ? ? ? ? ?intent.setClass(MainActivity.this,InfoActivity.class);

寫法三:? ComponentName 包裝Android組件

? ? ? ? ? ? ? ?Intent intent = new Intent();

? ? ? ? ? ? ? ?ComponentName cn = new? ComponentName(MainActivity.this,InfoActivity.class);

? ? ? ? ? ? ? ?intent.setComponent(cn);

(3)隱身意圖------action? ? ??

? ? ?不明確指定目標Activity署驻,而是通過Intent的動作action(通常用于多個應(yīng)用程序之間的跳轉(zhuǎn))? ? ??

? ? ?必須在android應(yīng)用中保持唯一? ? ??

? ? 目標Activity中必須聲明action屬性

? ? ?<intent-filter>

? ? ? ? ? ?<action ? android:name="com.qf.day06_lunchmode.CActivity"/>

? ? ? ? ? ?<category ?android.intent.category.DEFAULT"/>

? ? ?</intent-filter>

注意:action屬性一般需要和category屬性一起使用

訪問者:

方式一: Intent intent=new ?Intent();

? ? ? ? ? ? ? ? Intent();intent.setAction("com.qf.day06_lunchmode.CActivity");? ? ? ??

方式二:? ? ? ? ? ? ? ??

? ? ? ? ? ? ? Intent intent? = new Intent("com.qf.day06_lunchmode.CActivity"); ? ? ? ? ? ? ? ? ? ??

? ? ? ? ? ? ? android.setting.SETTINGS 設(shè)置頁面

? ? ? ? ? ? ? Intent.ACTION_DIAL? ? ? 撥號頁面

? ? ? ? ? ? ? Intent.ACTION_CALL? ? ? 撥打電話(直接呼出)

(4)category:表示action組件啟動的類型

? ? ? ? ? ? 一般android.intent.category.DEFAULT 代表普通的Activity組件

(5)data屬性:指定action后,將必須的屬性設(shè)置在此屬性中

? ? ? ? ? 如:打電話? 必須提供電話號碼

? ? ? ? ? ? ? ?打開網(wǎng)頁? ? 網(wǎng)址

? ? ? ? ?URI? 統(tǒng)一資源標識

? ? ? ? ? ? ? ? ?打電話: tel:53435343443

? ? ? ? ? ? ? ? ?發(fā)短信: smsto:760439045

? ? ? ? ? ? ? ? ?網(wǎng)址:? http://www.baidu.com

(6)type屬性:

? ? ? ? ? ?如果data屬性是文件的路徑,必須通過type來指定文件的類型

? ? ? ? ? ?圖片:? image/*

? ? ? ? ? ?文本:? text/*

? ? ? ? ? ?視頻:? video/*

? ? ? ? ? ?音頻:? audio/*

(7)extra 屬性:除了必須的屬性之外的擴展信息的屬性

? ? ? ? ? ? ? 常用于Android組件之間傳遞數(shù)據(jù)

(8)flag:組件的啟動模式 (參考Activity的啟動模式)

? ? ? ? ? ? 廣播接收器,啟動Activity組件式,必須指定flag屬

? ? ? ? ? ?性:FLAG_ACTIVITY_NEW_TASK

三.AsyncTask的使用

(1)定義一個類,繼承AsyncTask類,同時聲明三個泛型? ? ??

public class MyAsyncTask extends AsyncTask<String,Integer,Byte[]>

第一個參數(shù):? 子線程執(zhí)行方法的參數(shù)類型,對應(yīng)doinbackground的參數(shù)

第二個參數(shù):? 子線程執(zhí)行方法的進度,? ? 對應(yīng)onProgressUpdate的參數(shù)? 可以為空,Void首字母應(yīng)該大寫

第三個參數(shù):? 子線程執(zhí)行任務(wù)的結(jié)果返回類型,對應(yīng)onPostExecute的參數(shù)和doInbackground的返回值

(2)AsyncTask的四個核心方法(重寫)

? ? ? ? //運行在主線程中,執(zhí)行異步任務(wù)時,首先調(diào)用的方法,用于初始化

? ? ? ?<1>protected void onPreExecute()//運行在子線程中,執(zhí)行耗時的操作(后臺線程)

? ? ? ?<2>protected byte[] doInBackground(String... params)//運行在主線程中,用于更新 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 進度,更新前必須先手動 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 調(diào)用publishProgress()方 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?法

? ? ? <3>protected void onProgressUpdate(Integer...values)//運行在主線程中,在 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? doInbackground方法之后 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 執(zhí)行,系統(tǒng)自動調(diào)用

? ? ? <4>protected void onPostExecute(byte[] result)

(3)利用回調(diào)接口來實時更新進度

<1>定義一個回調(diào)接口

? ? ? ?public interface CallBack{

? ? ? ? ? ? ? ? ? ? ?public void callBack(int progress);回調(diào)方法,參數(shù)為進度的百分比

? ? ? ?}

<2>在訪問網(wǎng)絡(luò)的工具中聲明回調(diào)接口(HttpUtils工具類)

public? static String getJson(String path,CallBack callback){//以加載json字符串為例

? ? ? ? ? //獲取網(wǎng)絡(luò)資源的代碼

? ? ? ? ?//調(diào)用CallBack接口中的回調(diào)方法傳回進度

? ? ? ? ?callback.callBack(progress);

}

<3>在doInBackground方法中調(diào)用getJson方法,同實例化一個CallBack接口的匿名內(nèi)部類

protected byte[] donInBackground(String ... params){

? ? ? ? ? ?HttpUtils.getJson(params[0],new CallBack(){

? ? ? ? ? ? ? ? ? ? ? ? ? ? public void callBack(int progress){

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//當獲取網(wǎng)絡(luò)資源的代碼中調(diào)用此回調(diào)接口時,觸發(fā)此處代碼,并 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?傳回進度

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //拿到進度值,更新進度條

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? publishProgress(progress); //該方法將觸發(fā) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?onProgressUpdate(Integer..values);方法

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ?});

}

(4)取消異步任務(wù)

? ? ? ? (1)調(diào)用task.cancel(true);//true表示暴力取消,false溫柔取消

? ? ? ? (2)溫柔取消時系統(tǒng)會自動執(zhí)行onCancelled()方法

? ? ? ? ? ? ? protected void onCancelled() {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if(isCancelled()){

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Toast.makeText(MainActivity.this, "任務(wù)被取消!", ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Toast.LENGTH_LONG).show();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? }

四.ListView的總結(jié)

(1)主要屬性:

? ? ? ? ? ? ? ? ? android:divider = "#rgb"? Item之間的分割線的顏色,也可以是一張圖片

? ? ? ? ? ? ? ? ? android:dividerHeight = "1dp" Item之間的距離,通常為1dp

? ? ? ? ? ? ? ? ? android:entries="@array/name"? 用數(shù)組填充Item

(2)填充方式:? ? ??

? ? ? ? ?<1>屬性填充:? ? ? ? ??

? ? ? ? ? ? ? ? step1:先在strings.xml中定義數(shù)組

? ? ? ? ? ? ? ? ? ? ? ? ? ?<string_array name="citys">

? ? ? ? ? ? ? ? ? ? ? ? ? ?<item>北京</item>

? ? ? ? ? ? ? ? ? ? ? ? ? ?</string_array>

? ? ? ? ? ? ? ?step2:在listView中添加entries屬性? ? ? ?

? ? ? ? ? ? ? ? ? ? ? ? ? android:entries="@array/citys"

? ? ? ? ? ?<2>在Activity中通過適配器填充? ? ? ? ??

? ? ? ? ? ? ? ? ?①ArrayAdapter填充,適用于Item中只有一個文本? ? 數(shù)據(jù)源為:List<String>

? ? ? ? ? ? ? ? ?②SimpleAdapter填充,可以實現(xiàn)圖文混排的效果,但圖片必須是本地的(不能是從網(wǎng)絡(luò)獲取的)? ? 數(shù)據(jù)源為:List<Map<String,Object>>

?③自定義Adapter,創(chuàng)建自己的Adapter類繼承BaseAdapter抽象類,實現(xiàn)抽象方法? ? 數(shù)據(jù)源為:List<Map<String,Object>>或者ListM<javaBean>

? ? ? ? ?Step1:定義一個類繼承BaseAdapter

? ? ? ? ?Step2:實現(xiàn)四個抽象方法

? ? ? ? ? ? ? ? ? ? ?getCount()得到數(shù)據(jù)源的總長度

? ? ? ? ? ? ? ? ? ? ?getItem(int position)得到下標對應(yīng)的Item

? ? ? ? ? ? ? ? ? ? ?getItemId(int position)得到下標對應(yīng)的Item的Id

? ? ? ? ? ? ? ? ? ? ?getView(int position,View convertView,ViewGrioup parent)

? ? ? ? ? step3:在getView方法中為每個Item配置布局和數(shù)據(jù)

(3)ListView的事件監(jiān)聽器

? ? ? ? ?①Item單擊響應(yīng)事件

? ? ? ? ? ? ?OnItemClickListener

? ? ? ? ?②Item長按響應(yīng)事件

? ? ? ? ? ? ?OnItemLongClickListener

? ? ? ? ?③ListView滾動事件

? ? ? ? ? ? ? listview.setOnScrollListener(new OnScroolListener()){

? ? ? ? ? ? ? ? ? ? ?//該方法監(jiān)聽listView滾動狀態(tài)的改變

? ? ? ? ? ? ? ? ? ? ?//AbsListView ----- listView

? ? ? ? ? ? ? ? ? ? ?//int scrollState----滾動的狀態(tài)

? ? ? ? ? ? ? ? ? ? ?//三種滾動狀態(tài)對應(yīng)三個狀態(tài)碼

? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_TOUCH_SCROLL------1 listView正 ? ? ? ? ? ? ? ? ? ? ? 在滑動且手指還在屏幕上

? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_FLING --------2? listView慣性滑動

? ? ? ? ? ? ? ? ? ? //OnScrollListener.SCROLL_STATE_IDLE? --------0? listView停止滑動

? ? ? ? ? ? ? ? ? ?public void onScrollStateChanged(AbsListView view,int scrollState){

? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ? ? ?//該方法監(jiān)聽listView滾動的方法

? ? ? ? ? ? ? ? ? ?//AbslistView view------listView

? ? ? ? ? ? ? ? ? //int firstVisibleItem ------當前屏幕最上方顯示的Item的下標

? ? ? ? ? ? ? ? ? //int visibleItemCount ------當前屏幕顯示Item的個數(shù),半個也算

? ? ? ? ? ? ? ? ? //int totalItemCount? -------當前所有Item的總數(shù)

? ? ? ? ? ? ? ? ? public void onScroll(AbsListView view,int firstVisibleItem,

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? int visibleItemCount,int totalItemCount){

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //小技巧:判斷是否滑動到最底部

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?Boolean islast = (firstVisible+visibleItemCount==totalItemCount);

? ? ? ? ? ? ? ? ? }

}

(4)ListView 的優(yōu)化

①屬性優(yōu)化:

? ? ? ? ? ? ? ? ? ? android:layout_width="match_parent"

? ? ? ? ? ? ? ? ? ? android:layout_height="match_parent"

? ? ? ? ? ? ? ? ? ? ?如果是wrap_content,加載時每條Item會執(zhí)行多次來計算ListView的寬高

②重用convertView對象,將Item布局緩存起來從而復(fù)用

③定義ViewHolder類,減少findViewById的次數(shù)

參考代碼:

public View getView(int position, View convertView, ViewGroup parent) {

? ? ? ? ? ? ? ? ? ? ViewHolder holder;

? ? ? ? ? ? ? ? ? ? if (convertView == null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder = new ViewHolder();

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView = View.inflate(context, R.layout.item_listview, null);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder.textViewName = (TextView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView.findViewById(R.id.name);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.textViewDescription = (TextView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.findViewById(R.id.description);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.setTag(holder);

? ? ? ? ? ? ? ? ? ? ? ?} else {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? holder = (ViewHolder) convertView.getTag();

? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? holder.textViewName.setText(list.get(position).getName());

? ? ? ? ? ? ? ? ? ? ? holder.textViewDescription.setText(list.get(position).getDescription());

? ? ? ? ? ? ? ? ? ? ? return convertView;

}

(5)ListView加載網(wǎng)絡(luò)圖片,實現(xiàn)圖文混排

通常圖片地址在Json數(shù)據(jù)中或者XML文件中.(以json為例)

<1>通過網(wǎng)絡(luò)加載json數(shù)據(jù),然后解析封裝成類

<2>在ListView的Adapter中構(gòu)建Item時,

如果是文本內(nèi)容則直接設(shè)置,如果為圖片內(nèi)容則開啟異步任務(wù)去網(wǎng)絡(luò)中加載

<3>對加載好的圖片進行緩存,當?shù)诙涡枰故镜臅r候,直接在內(nèi)存中加載而不用訪問網(wǎng)絡(luò)

此處用Map來緩存(只是模擬),其他緩存方式后續(xù)更新

<4>由于convertView的復(fù)用,和異步任務(wù)形成的時間差,會造成圖片錯位現(xiàn)象

通過為ImageView打標簽可以解決圖片錯位的問題

代碼:??

Map<String,Bitmap> map = new HashMap<String,Bitmap>();

ViewHolder holder;

public View getView(int position, View convertView, ViewGroup parent) {

? ? ? ? ? ? if (convertView == null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? holder = new ViewHolder();

? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView = View.inflate(context, R.layout.item_listview, null);

? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.imageView = (ImageView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?convertView.findViewById(R.id.image);

? ? ? ? ? ? ? ? ? ? ? ? ? ? holder.textViewName = (TextView) convertView

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? .findViewById(R.id.name);

? ? ? ? ? ? ? ? ? ? ? ? ? ? convertView.setTag(holder);

? ? ? ? ? ? ? ?} else {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder = (ViewHolder) convertView.getTag();

? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?holder.imageView.setImageResource(R.drawable.ic_launcher);//用于清空被 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 重用的holder中攜帶的圖片內(nèi)容

? ? ? ? ? ? ? ?String curImageUrl = list.get(position).getCoverUrl();

? ? ? ? ? ? ? ?holder.imageView.setTag(curImageUrl);//為ImageView打標簽,用此 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?imageView要顯示圖片的地址最為標簽

? ? ? ? ? ? ? ?if (!map.containsKey(curImageUrl)) {//判斷Map中是否存有該地址(圖片資源)

? ? ? ? ? ? ? ? ? ? ? ? ?//如果Map中沒有緩存,說明是第一次加載此圖片,需要從網(wǎng)絡(luò)獲取

? ? ? ? ? ? ? ? ? ? ? ? ?new ImageAsyncTask(new CallBack() {//開啟異步任務(wù)加載圖片

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? @Override

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?public void callBack(String path, Bitmap bitmap) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?//通過回調(diào)方法返回加載圖片資源和其地址

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //將加載好的圖片資源和地址存入Map進行緩存

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? map.put(path, bitmap);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ImageView imageView = (ImageView) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? listView.findViewWithTag(path);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //通過標簽在ListView中找到對應(yīng)的imageView,并為其 ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?設(shè)置圖片資源

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?if (imageView != null) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?imageView.setImageBitmap(bitmap);

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }).execute(curImageUrl);

? ? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //如果Map中緩存的有需要的圖片,則直接拿過來使用

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?holder.imageView.setImageBitmap(map.get(curImageUrl));

? ? ? ? ? ? ? ?}

? ? ? ? ? ? ? ?holder.textViewName.setText(list.get(position).getName());

? ? ? ? ? ? ? ? return convertView;

}

class ViewHolder {

? ? ? ? ? ? ? ? ? ? ImageView imageView;

? ? ? ? ? ? ? ? ? ?TextView textViewName;

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末迎瞧,一起剝皮案震驚了整個濱河市检诗,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌硼被,老刑警劉巖,帶你破解...
    沈念sama閱讀 223,126評論 6 520
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件猛蔽,死亡現(xiàn)場離奇詭異黄刚,居然都是意外死亡,警方通過查閱死者的電腦和手機诫尽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,421評論 3 400
  • 文/潘曉璐 我一進店門禀酱,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人牧嫉,你說我怎么就攤上這事剂跟。” “怎么了酣藻?”我有些...
    開封第一講書人閱讀 169,941評論 0 366
  • 文/不壞的土叔 我叫張陵曹洽,是天一觀的道長。 經(jīng)常有香客問我辽剧,道長送淆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,294評論 1 300
  • 正文 為了忘掉前任怕轿,我火速辦了婚禮偷崩,結(jié)果婚禮上辟拷,老公的妹妹穿的比我還像新娘。我一直安慰自己阐斜,他們只是感情好衫冻,可當我...
    茶點故事閱讀 69,295評論 6 398
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著谒出,像睡著了一般羽杰。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上到推,一...
    開封第一講書人閱讀 52,874評論 1 314
  • 那天,我揣著相機與錄音惕澎,去河邊找鬼莉测。 笑死,一個胖子當著我的面吹牛唧喉,可吹牛的內(nèi)容都是我干的捣卤。 我是一名探鬼主播,決...
    沈念sama閱讀 41,285評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼八孝,長吁一口氣:“原來是場噩夢啊……” “哼董朝!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起干跛,我...
    開封第一講書人閱讀 40,249評論 0 277
  • 序言:老撾萬榮一對情侶失蹤子姜,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后楼入,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哥捕,經(jīng)...
    沈念sama閱讀 46,760評論 1 321
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,840評論 3 343
  • 正文 我和宋清朗相戀三年嘉熊,在試婚紗的時候發(fā)現(xiàn)自己被綠了遥赚。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,973評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡阐肤,死狀恐怖凫佛,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情孕惜,我是刑警寧澤愧薛,帶...
    沈念sama閱讀 36,631評論 5 351
  • 正文 年R本政府宣布,位于F島的核電站诊赊,受9級特大地震影響厚满,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜碧磅,卻給世界環(huán)境...
    茶點故事閱讀 42,315評論 3 336
  • 文/蒙蒙 一碘箍、第九天 我趴在偏房一處隱蔽的房頂上張望遵馆。 院中可真熱鬧,春花似錦丰榴、人聲如沸货邓。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,797評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽换况。三九已至,卻和暖如春盗蟆,著一層夾襖步出監(jiān)牢的瞬間戈二,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,926評論 1 275
  • 我被黑心中介騙來泰國打工喳资, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留觉吭,地道東北人。 一個月前我還...
    沈念sama閱讀 49,431評論 3 379
  • 正文 我出身青樓仆邓,卻偏偏與公主長得像鲜滩,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子节值,可洞房花燭夜當晚...
    茶點故事閱讀 45,982評論 2 361

推薦閱讀更多精彩內(nèi)容