/* * Copyright (C) 2009 Teleca Poland Sp. z o.o. <android@teleca.com> * * 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 grimbo.android.demo.adapter; import java.util.ArrayList; import android.app.Activity; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ListView; /** * Nice wrapper-abstraction around ArrayList * * @author Lukasz Wisniewski * * @param <T> */ public abstract class ArrayListAdapter<T> extends BaseAdapter{ protected ArrayList<T> mList; protected Activity mContext; protected ListView mListView; public ArrayListAdapter(Activity context){ this.mContext = context; } @Override public int getCount() { if(mList != null) return mList.size(); else return 0; } @Override public Object getItem(int position) { return mList == null ? null : mList.get(position); } @Override public long getItemId(int position) { return position; } @Override abstract public View getView(int position, View convertView, ViewGroup parent); public void setList(ArrayList<T> list){ this.mList = list; notifyDataSetChanged(); } public ArrayList<T> getList(){ return mList; } public void setList(T[] list){ ArrayList<T> arrayList = new ArrayList<T>(list.length); for (T t : list) { arrayList.add(t); } setList(arrayList); } public ListView getListView(){ return mListView; } public void setListView(ListView listView){ mListView = listView; } }
使用方法
1、自定义一个adapter
public class PurpleAdapter extends ArrayListAdapter<PurpleEntry>
2、
//存入一个自定义泛型 private ArrayList<PurpleEntry> browseListEntry; mBrowseJamendoPurpleAdapter.setList(browseListEntry);
3、在自定义PurpleAdapter 中使用
if(mList.get(position).getText() != null){ holder.text.setText(mList.get(position).getText());
相关推荐
自定义View入门,博客地址: http://blog.csdn.net/jsonnan/article/details/73826185
这是一个通过xml文件自定义view的一个Demo
给超链接自定义一个右键菜单 给超链接自定义一个右键菜单 给超链接自定义一个右键菜单
自定义一个仪表盘
闲得蛋疼,自定义一个pickView玩玩,挺好用的
PowerConsumptionRankingsBatteryView 自定义一个电池View
教你如何自定义一个神经网络,并进行权值的初始化,网络的训练和仿真
iPhone开发学习笔记005——使用XIB自定义一个UIView,然后将这个view添加到controller的view。
Android 自定义控件之简单自定义一个TopBar,AndroidStudio环境下做的
利用自定义事件做的一个可以控制progressbar进度的例子,和大家分享一下
一个对话框自定义消息,用来接收另一个对话框的消息。在vs2008下编译执行通过.
java web项目一个自定义的分页标签
C# 自定义控件 自定义ComboBox。其他控件的自定义与此类似。
PB自定义button控件 带移入移出效果 自定义背景色 边框
学习android当中自定义view的一些常用绘图技巧,优化android绘图操作
创建全新的视图将满足我们独特的UI需求。 本文介绍在指南针开发中会用到的罗盘的界面UI,通过继承View类实现的自定义视图,以此来深刻了解自定义视图。
vb.net 自定义控件 自定义属性 UITypeEditor UI 类型编辑器 ...注意一个问题:设计模式与生成dll文件加载显示结果不同,这就是为什么会在设计模式时运行显示灰色,不能跳出自定义对话框,只有在生成文件加载才显示。
vue手写一个自定义操作的工作流:适用简单的、想要手写的、不借用三方插件的工作流开发。样式自定义,可随意扩展、随意添加条件、自定义条件
Qt5实现自定义控件默认一个DLL文件中只能包含一个控件,在参考Qwt6.1.3的源码后,实现一个dll文件内包含多个控件,并在Designer内集成,实际使用测试。压缩包内包含说明文档及示例。
这是一个自定义控件的demo,包含自定义的属性。通过自定义属性给一个布局文件中的控件设置标题。希望对大家有帮助。