久久久精品一区ed2k-女人被男人叉到高潮的视频-中文字幕乱码一区久久麻豆樱花-俄罗斯熟妇真实视频

AndroidStickyListHeaders實(shí)現(xiàn)電話本列表效果

本文實(shí)例為大家分享了StickyListHeaders電話本列表效果的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)公司從2013年開(kāi)始,先為錦江等服務(wù)建站,錦江等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢(xún)服務(wù)。為錦江企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。

效果展示

Android StickyListHeaders實(shí)現(xiàn)電話本列表效果

布局文件

與listview使用方式一樣,可以在布局文件中直接進(jìn)行使用

核心代碼

oncreat方法

在oncreat方法中初始化控件,并為控件設(shè)置數(shù)據(jù)適配器

StickyListHeadersListView stickyList = (StickyListHeadersListView) findViewById(R.id.list);
MyAdapter adapter = new MyAdapter(this);
stickyList.setAdapter(adapter);

設(shè)置數(shù)據(jù)適配器

在設(shè)置數(shù)據(jù)適配器的時(shí)候,需要先繼承BaseAdapter,然后實(shí)現(xiàn)StickyListHeadersAdapter接口,最后實(shí)現(xiàn)里面為實(shí)現(xiàn)的方法

public class MyAdapter extends BaseAdapter implements StickyListHeadersAdapter {

private String[] countries;
private LayoutInflater inflater;

public MyAdapter(Context context) {
 inflater = LayoutInflater.from(context);
 countries = context.getResources().getStringArray(R.array.countries);
}

@Override
public int getCount() {
 return countries.length;
}

@Override
public Object getItem(int position) {
 return countries[position];
}

@Override
public long getItemId(int position) {
 return position;
}

@Override 
public View getView(int position, View convertView, ViewGroup parent) {
 ViewHolder holder;

 if (convertView == null) {
  holder = new ViewHolder();
  convertView = inflater.inflate(R.layout.test_list_item_layout, parent, false);
  holder.text = (TextView) convertView.findViewById(R.id.text);
  convertView.setTag(holder);
 } else {
  holder = (ViewHolder) convertView.getTag();
 }

 holder.text.setText(countries[position]);

 return convertView;
}

@Override 
public View getHeaderView(int position, View convertView, ViewGroup parent) {
 HeaderViewHolder holder;
 if (convertView == null) {
  holder = new HeaderViewHolder();
  convertView = inflater.inflate(R.layout.header, parent, false);
  holder.text = (TextView) convertView.findViewById(R.id.text);
  convertView.setTag(holder);
 } else {
  holder = (HeaderViewHolder) convertView.getTag();
 }
 //set header text as first char in name
 String headerText = + countries[position].subSequence(0, 1).charAt(0);
 holder.text.setText(headerText);
 return convertView;
}

@Override
public long getHeaderId(int position) {
 //return the first character of the country as ID because this is what headers are based upon
 return countries[position].subSequence(0, 1).charAt(0);
}

class HeaderViewHolder {
 TextView text;
}

class ViewHolder {
 TextView text;
}

}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

新聞標(biāo)題:AndroidStickyListHeaders實(shí)現(xiàn)電話本列表效果
地址分享:http://sd-ha.com/article16/gcjcgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、外貿(mào)網(wǎng)站建設(shè)、Google網(wǎng)站改版、服務(wù)器托管響應(yīng)式網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作