android自定义列表的实现
来源:互联网 发布:无损音乐 知乎 编辑:程序博客网 时间:2024/04/28 14:34
android自定义列表的实现
前面实现的列表功能都是直接调用android的api,功能比较简单。这里需要实现一个自定义的视频内容列表。效果如下:
需要在前面例子android使用TabContentFactory创建标签内视图基础上,实现一个自定义的列表适配器类:
private class ContentAdapter extends ArrayAdapter<Content> {
private List<Content> items;
public ContentAdapter(Context context, int textViewResourceId,
List<Content> items) {
super(context, textViewResourceId, items);
this.items = items;
}@Override
public View getView(int position, View convertView, ViewGroup parent) {
View view = convertView;if (view == null) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = inflater.inflate(R.layout.content, null);
}Content content = items.get(position);
if (content != null) {
TextView title = (TextView) view
.findViewById(R.id.ContentTitle);
TextView comment = (TextView) view
.findViewById(R.id.ContentComment);
ImageView imageView = (ImageView) view.findViewById(R.id.image);title.setText(content.getTitle());
comment.setText(content.getComment());
imageView.setImageDrawable(CustomerPlayer.this.getResources()
.getDrawable(Integer.parseInt(content.getImageUrl())));
}return view;
}
}
和该适配器中对应的列表元素布局文件:
<?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="wrap_content"
android:orientation="vertical" android:textAppearance="?android:attr/textAppearanceLarge"
android:minHeight="?android:attr/listPreferredItemHeight"
android:paddingLeft="6dip" android:paddingBottom="6dip">
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal"
android:padding="5dip">
<ImageView android:id="@+id/image" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:paddingRight="10dip" />
<TextView android:id="@+id/ContentTitle"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:textStyle="bold" android:textSize="20px"></TextView>
</LinearLayout>
<TextView android:id="@+id/ContentComment"
android:layout_width="fill_parent" android:layout_height="wrap_content"></TextView>
</LinearLayout>
这样就可以这样调用生成列表了:
tabHost.addTab(tabHost.newTabSpec("tab1").setIndicator("栏目内容")
.setContent(new TabContentFactory() {List<Content> items;
{
items = new ArrayList<Content>();
Content content = new Content();
content.setTitle("阿童木");
content
.setComment("因意外痛失爱子的天才科学家天马博士悲痛欲绝,萌生了复制爱子的想法并成功创造了机器人阿童木,他和人类一样拥有喜怒哀乐,而且还有博士儿子残余的情感与记忆。但阿童木却无法令抑郁的博士重展欢颜,博士狠心决定将他遗弃…");
content.setImageUrl("" + R.drawable.c1);
items.add(content);content = new Content();
content.setTitle("三枪拍案惊奇");
content
.setComment("故事发生于古代某大漠之中,一家面馆老板名为王五麻子,为人阴险吝啬,如此人品,老婆自然不待见。恰好伙计李四长得很帅又有幽默感,两人一拍即合,有了私情。王五发现两人私情后…");
content.setImageUrl("" + R.drawable.c2);
items.add(content);content = new Content();
content.setTitle("花木兰");
content
.setComment("在古老的中国,有一位个性爽朗,性情善良的好女孩,名字叫作「花木兰」,身为花家的大女儿,花木兰在父母开明的教悔下,一直很期待自己能花家带来荣耀。不过就在北方匈奴来犯…");
content.setImageUrl("" + R.drawable.c3);
items.add(content);content = new Content();
content.setTitle("达芬奇密码");
content
.setComment("本片讲述了哈佛大学的符号学专家罗伯特·兰登在法国巴黎出差期间的一个午夜接到一个紧急电话,得知卢浮宫博物馆年迈的馆长被人杀害在卢浮宫的博物馆里,人们在他的尸体旁边发现了一个难以捉摸的密码…");
content.setImageUrl("" + R.drawable.c4);
items.add(content);
}@Override
public View createTabContent(String tag) {
ListView listView = new ListView(CustomerPlayer.this);
listView.setAdapter(new ContentAdapter(
CustomerPlayer.this, 0, items));return listView;
}
}));
源代码见:
http://easymorse.googlecode.com/svn/tags/android.customer.player-0.4/
- android自定义列表的实现
- android 手把手实现自定义列表
- 【Android基础篇】使用ExpandableListView实现自定义的下拉列表
- 【Android基础篇】使用ExpandableListView实现自定义的下拉列表
- android自定义列表的修饰
- android自定义列表的修饰
- Android实现自定义个性化下拉列表
- Android 自定义View实现城市选择列表
- 使用PopupWindow实现的自定义下拉列表
- 使用自定义的RelateLayout实现列表布局
- Android实现RecyclerView自定义列表,SwipeRefreshLayout实现下拉刷新
- 2014-10-27Android学习------自定义widget的监听事件的实现-----城市列表应用程序
- Android -- 自定义实现横竖双向滚动的列表(ListView)布局
- Android复杂列表的实现
- Android自定义列表(ListView)
- Android自定义列表(ListView)
- Android 自定义下拉列表
- Android 自定义下拉列表
- C# ASP.NET 开源网上商城、外贸产品网上展示的几个效果图 -- 仅供大家参考
- 信息系统,分层不要过多,静态方法也可以考虑适当多用
- 关于沙盒
- 【自然框架】用CMS的栏目举例,聊一聊从“一层”到“三层”的变化
- 每日学习笔记(2)
- android自定义列表的实现
- C++头文件重复定义问题的处理(转)
- conn.setAutoCommit(false)
- Windows NLB搭配IIS的ARR搭建高可用环境
- ExpandInfoAdapter实现二级列表显示
- C#带进度条和百分比的窗体实现过程
- Linux汇编语言开发指南,Linux汇编器
- 运行时异常与非运行时异常有什么区别
- android利用onSearchRequested()调用内部搜索ui组件