www.久久久久|狼友网站av天堂|精品国产无码a片|一级av色欲av|91在线播放视频|亚洲无码主播在线|国产精品草久在线|明星AV网站在线|污污内射久久一区|婷婷综合视频网站

當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]聊天界面會(huì)展示至少兩種布局,即收到消息和發(fā)送消息。這樣一個(gè)ListView與平時(shí)使用的ListView的最大不同,在于它有兩個(gè)不同的布局:收到的布局和發(fā)送的布局。需要利用Adapter實(shí)現(xiàn)這樣的效果。

聊天界面會(huì)展示至少兩種布局,即收到消息和發(fā)送消息。這樣一個(gè)ListView與平時(shí)使用的ListView的最大不同,在于它有兩個(gè)不同的布局:收到的布局和發(fā)送的布局。需要利用Adapter實(shí)現(xiàn)這樣的效果。即需要在獲取布局的時(shí)候判斷該獲取哪個(gè)布局。

public abstract class BaseAdapter extends Object
implements ListAdapter SpinnerAdapter java.lang.Object ???? android.widget.BaseAdapter

BaseAdapter這個(gè)類中提供了兩個(gè)方法:

public intgetItemViewType (int position) Added in API level 1

Get the type of View that will be created by getView(int, View, ViewGroup) for the specified item.

ParametersThe position of the item within the adapter's data set whose view type we want. Returns? 返回第position個(gè)Item是何種類型 An integer representing the type of View. Two views should share the same type if one can be converted to the other ingetView(int, View, ViewGroup). Note: Integers must be in the range 0 togetViewTypeCount() - 1. IGNORE_ITEM_VIEW_TYPE can also be returned.

?

public intgetViewTypeCount () Added in API level 1


Returns the number of types of Views that will be created by getView(int, View, ViewGroup). Each type represents a set of views that can be converted ingetView(int, View, ViewGroup). If the adapter always returns the same type of View for all items, this method should return 1.

This method will only be called when when the adapter is set on the the AdapterView.


Returns 返回不同布局的數(shù)目 The number of types of Views that will be created by this adapter

首先需要實(shí)現(xiàn)兩個(gè)布局——發(fā)送和接收

chat_item_itemin.xml

?

"


chat_item_itemout.xml



?

?

為了封裝聊天內(nèi)容,便于在Adapter中獲取數(shù)據(jù)信息,封裝一個(gè)Bean類來(lái)保存聊天信息。編寫(xiě)javabean就是編寫(xiě)一個(gè)java的類,所以只要會(huì)寫(xiě)類就能編寫(xiě)一個(gè)bean,這個(gè)類創(chuàng)建的一個(gè)對(duì)象稱做一個(gè)bean。為了能讓使用這個(gè)bean的應(yīng)用程序構(gòu)建工具(比如JSP引擎)知道這個(gè)bean的屬性和方法,只需在類的方法命名上遵守以下規(guī)則:

1. 如果類的成員變量的名字是xxx,那么為了更改或獲取成員變量的值,即更改或獲取屬性,在類中可以使用兩個(gè)方法:

getXxx(),用來(lái)獲取屬性xxx。

setXxx(),用來(lái)修改屬性xxx。

2. 對(duì)于boolean類型的成員變量,即布爾邏輯類型的屬性,允許使用"is"代替上面的"get"和"set"。

3. 類中方法的訪問(wèn)屬性都必須是public的。

4. 類中如果有構(gòu)造方法,那么這個(gè)構(gòu)造方法也是public的并且是無(wú)參數(shù)的。

?

ChatItemListViewBean.java

package?sunny.example.ahfourlistviewchat;

//封裝一個(gè)Bean來(lái)保存聊天信息
import?android.graphics.Bitmap;
public?class?ChatItemListViewBean?{

	private?int?type;
	private?String?text;
	private?Bitmap?icon;
	
	public?ChatItemListViewBean(){
		
	}
	
	public?int?getType(){
		return?type;
	}
	//在使用時(shí)setType?如bean1.setType(0);
	public?void?setType(int?type){
		this.type?=?type;
	}
	
	public?String?getText(){
		return?text;
	}
	
	public?void?setText(String?text){
		this.text?=?text;
	}
	
	public?Bitmap?getIcon(){
		return?icon;
	}
	
	public?void?setIcon(Bitmap?icon){
		this.icon?=?icon;
	}
}

activity_main.xml


?

ChatItemListViewTest.java

package?sunny.example.ahfourlistviewchat;

import?android.support.v7.app.ActionBarActivity;
import?android.widget.ListView;
import?android.graphics.BitmapFactory;
import?android.os.Bundle;
import?java.util.List;
import?java.util.ArrayList;
public?class?ChatItemListViewTest?extends?ActionBarActivity{

	private?ListView?mListView;
	protected?void?onCreate(Bundle?savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mListView?=?(ListView)findViewById(R.id.listView_chat);
		ChatItemListViewBean?bean1?=?new?ChatItemListViewBean();
		bean1.setType(0);
		bean1.setIcon(BitmapFactory.decodeResource(getResources(),?R.drawable.ic_launcher));
		bean1.setText("Hello.?How?are?you?");
		
		ChatItemListViewBean?bean2?=?new?ChatItemListViewBean();
		bean2.setType(1);
		bean2.setIcon(BitmapFactory.decodeResource(getResources(),?R.drawable.ic_launcher));
		bean2.setText("Fine.?Thank?you");
		
		Listdata?=?new?ArrayList();
		data.add(bean1);
		data.add(bean2);
		mListView.setAdapter(new?ChatItemListViewAdapter(this,data));
	}
}



?

position
本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車(chē)的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車(chē)技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車(chē)工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車(chē)。 SODA V工具的開(kāi)發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車(chē) 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來(lái)越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來(lái)越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開(kāi)幕式在貴陽(yáng)舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語(yǔ)權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉