当前位置: 首页 > news >正文

网站字体特效/seo关键词推广怎么做

网站字体特效,seo关键词推广怎么做,2021中国建筑企业500强排名,wordpress显示用户列表利用ViewHolder优化自定义Adapter的典型写法 最近写Adapter写得多了,慢慢就熟悉了。 用ViewHolder,主要是进行一些性能优化,减少一些不必要的重复操作。(WXD同学教我的。) 具体不分析了,直接上一份代码吧&a…

 

利用ViewHolder优化自定义Adapter的典型写法

 

  最近写Adapter写得多了,慢慢就熟悉了。

  用ViewHolder,主要是进行一些性能优化,减少一些不必要的重复操作。(WXD同学教我的。)

  具体不分析了,直接上一份代码吧:

public class MarkerItemAdapter extends BaseAdapter
{private Context mContext = null;private List<MarkerItem> mMarkerData = null;public MarkerItemAdapter(Context context, List<MarkerItem> markerItems){mContext = context;mMarkerData = markerItems;}public void setMarkerData(List<MarkerItem> markerItems){mMarkerData = markerItems;}@Overridepublic int getCount(){int count = 0;if (null != mMarkerData){count = mMarkerData.size();}return count;}@Overridepublic MarkerItem getItem(int position){MarkerItem item = null;if (null != mMarkerData){item = mMarkerData.get(position);}return item;}@Overridepublic long getItemId(int position){return position;}@Overridepublic View getView(int position, View convertView, ViewGroup parent){ViewHolder viewHolder = null;if (null == convertView){viewHolder = new ViewHolder();LayoutInflater mInflater = LayoutInflater.from(mContext);convertView = mInflater.inflate(R.layout.item_marker_item, null);viewHolder.name = (TextView) convertView.findViewById(R.id.name);viewHolder.description = (TextView) convertView.findViewById(R.id.description);viewHolder.createTime = (TextView) convertView.findViewById(R.id.createTime);convertView.setTag(viewHolder);}else{viewHolder = (ViewHolder) convertView.getTag();}// set item values to the viewHolder:
MarkerItem markerItem = getItem(position);if (null != markerItem){viewHolder.name.setText(markerItem.getName());viewHolder.description.setText(markerItem.getDescription());viewHolder.createTime.setText(markerItem.getCreateDate());}return convertView;}private static class ViewHolder{TextView name;TextView description;TextView createTime;}}

 

  其中MarkerItem是自定义的类,其中包含name,description,createTime等字段,并且有相应的get和set方法。

 

  ViewHolder是一个内部类,其中包含了单个项目布局中的各个控件。

  单个项目的布局,即R.layout.item_marker_item如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" android:padding="5dp"><TextViewandroid:id="@+id/name"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Name"android:textSize="20sp"android:textStyle="bold" /><TextViewandroid:id="@+id/description"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="Description"android:textSize="18sp" /><TextViewandroid:id="@+id/createTime"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="CreateTime"android:textSize="16sp" /></LinearLayout>

 

官方的API Demos中也有这个例子:

package com.example.android.apis.view中的List14:

/** Copyright (C) 2008 The Android Open Source Project** Licensed under the Apache License, Version 2.0 (the "License");* you may not use this file except in compliance with the License.* You may obtain a copy of the License at**      http://www.apache.org/licenses/LICENSE-2.0** Unless required by applicable law or agreed to in writing, software* distributed under the License is distributed on an "AS IS" BASIS,* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.* See the License for the specific language governing permissions and* limitations under the License.*/package com.example.android.apis.view;import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import android.widget.ImageView;
import android.graphics.BitmapFactory;
import android.graphics.Bitmap;
import com.example.android.apis.R;/*** Demonstrates how to write an efficient list adapter. The adapter used in this example binds* to an ImageView and to a TextView for each row in the list.** To work efficiently the adapter implemented here uses two techniques:* - It reuses the convertView passed to getView() to avoid inflating View when it is not necessary* - It uses the ViewHolder pattern to avoid calling findViewById() when it is not necessary** The ViewHolder pattern consists in storing a data structure in the tag of the view returned by* getView(). This data structures contains references to the views we want to bind data to, thus* avoiding calls to findViewById() every time getView() is invoked.*/
public class List14 extends ListActivity {private static class EfficientAdapter extends BaseAdapter {private LayoutInflater mInflater;private Bitmap mIcon1;private Bitmap mIcon2;public EfficientAdapter(Context context) {// Cache the LayoutInflate to avoid asking for a new one each time.mInflater = LayoutInflater.from(context);// Icons bound to the rows.mIcon1 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_1);mIcon2 = BitmapFactory.decodeResource(context.getResources(), R.drawable.icon48x48_2);}/*** The number of items in the list is determined by the number of speeches* in our array.** @see android.widget.ListAdapter#getCount()*/public int getCount() {return DATA.length;}/*** Since the data comes from an array, just returning the index is* sufficent to get at the data. If we were using a more complex data* structure, we would return whatever object represents one row in the* list.** @see android.widget.ListAdapter#getItem(int)*/public Object getItem(int position) {return position;}/*** Use the array index as a unique id.** @see android.widget.ListAdapter#getItemId(int)*/public long getItemId(int position) {return position;}/*** Make a view to hold each row.** @see android.widget.ListAdapter#getView(int, android.view.View,*      android.view.ViewGroup)*/public View getView(int position, View convertView, ViewGroup parent) {// A ViewHolder keeps references to children views to avoid unneccessary calls// to findViewById() on each row.
            ViewHolder holder;// When convertView is not null, we can reuse it directly, there is no need// to reinflate it. We only inflate a new View when the convertView supplied// by ListView is null.if (convertView == null) {convertView = mInflater.inflate(R.layout.list_item_icon_text, null);// Creates a ViewHolder and store references to the two children views// we want to bind data to.holder = new ViewHolder();holder.text = (TextView) convertView.findViewById(R.id.text);holder.icon = (ImageView) convertView.findViewById(R.id.icon);convertView.setTag(holder);} else {// Get the ViewHolder back to get fast access to the TextView// and the ImageView.holder = (ViewHolder) convertView.getTag();}// Bind the data efficiently with the holder.
            holder.text.setText(DATA[position]);holder.icon.setImageBitmap((position & 1) == 1 ? mIcon1 : mIcon2);return convertView;}static class ViewHolder {TextView text;ImageView icon;}}@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setListAdapter(new EfficientAdapter(this));}private static final String[] DATA = Cheeses.sCheeseStrings;
}

   其中布局:

 

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2007 The Android Open Source ProjectLicensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.
--><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="horizontal"android:layout_width="match_parent"android:layout_height="match_parent"><ImageView android:id="@+id/icon"android:layout_width="48dip"android:layout_height="48dip" /><TextView android:id="@+id/text"android:layout_gravity="center_vertical"android:layout_width="0dip"android:layout_weight="1.0"android:layout_height="wrap_content" /></LinearLayout>

 

更多关于Adapter优化的文章:

  http://www.cnblogs.com/over140/archive/2011/03/23/1991100.html

  http://www.cnblogs.com/halzhang/archive/2010/12/05/1896791.html

 

 

http://www.lbrq.cn/news/1403353.html

相关文章:

  • 网站建设优化是什么鬼/关键词权重如何打造
  • 涞水县住房和城乡建设局网站/郴州网站推广
  • 网站付费推广/网站快速优化排名app
  • 上海建站市场/百度推广上班怎么样
  • 做网站做百度竞价赚钱/网络推广公司联系方式
  • 想要给网站加视频怎么做/seo实战培训机构
  • php网站开发技术是什么/长沙网站设计
  • 苏州网站建设科技/中国目前最好的搜索引擎
  • 青岛模板网站建设价格/抖音关键词排名查询工具
  • 南宁seo推广外包/百度竞价优化
  • 阜阳市住房和城乡建设局网站/百度的网页地址
  • 架子鼓谱那个网站做的好/it培训机构出来能找到工作吗
  • 长沙网站seo/电商培训
  • 网站怎么建设的/百度拍照搜索
  • 网站制作售后/江门百度seo公司
  • 盘锦做网站建设的/如何做好宣传推广
  • 有什么做动画的网站/东莞建设网
  • 做网站赚钱一般做什么/交换链接是什么
  • 网站界面是什么做的/温州seo
  • 旅游网站怎么建设/网站seo招聘
  • 做网站的图片大小是多少/开发定制软件公司
  • 摄影网站模板源码/公司推广方案
  • 北京住房和城乡建设部网站官网/软文大全
  • 珠宝商城网站设计/网站seo优化发布高质量外链
  • 做浏览单的网站有哪些/免费com域名注册永久
  • 政府网站建设怎么谈需求/营销型网站有哪些平台
  • 网站建设有哪些企业/推手平台哪个靠谱
  • 中国装修第一网/企业网站优化服务公司
  • 江苏省建筑工程网/兰州seo快速优化报价
  • 响应式门户网站/关联词有哪些五年级
  • PCL+Spigot服务器+python进行MC编程(使用Trae进行AI编程)---可以生成彩虹
  • 决策树1.1
  • ReLens「Focus DSLR 大光圈虚化相机」v4.1.2 f 解锁付款版 —一款专业大光圈和单反级背景虚化编辑软件
  • 基于ssm jsp中学校园网站源码和答辩PPT论文
  • 解锁 JavaScript 高级技能:从基础到实战的进阶指南
  • mybatis连接数据库