- 浏览: 237200 次
- 性别:
- 来自: 武汉
文章分类
- 全部博客 (195)
- android开发 (29)
- JAVA (3)
- android—Task (1)
- android—Folders (1)
- android—gallery (1)
- android—ListView (15)
- android—GridView (4)
- android—Notification (3)
- android—File (5)
- android—tabhost (3)
- android—uri (4)
- android—Shortcut (1)
- android—Imei (1)
- android—Vibrator (3)
- android—Voice (1)
- android 小案例练习 (2)
- android—Wifi (1)
- android—login (1)
- android—onKeyDown (1)
- android—Activity (12)
- android—onTouchEvent (2)
- android—thread (2)
- android—app (3)
- android—webview (2)
- android—Activity自动跳转 (2)
- android_sensor (1)
- android_URL (2)
- android—Googlemap (1)
- android TextView小练习 (1)
- android-apk (1)
- android -sqlite (2)
- Java -xml (1)
- rest (1)
- android-phone (2)
- android—image (7)
- android_intent (3)
- android——broadcastReceiver (2)
- Map (1)
- lock (0)
- android-background (2)
- android-cache (2)
- android-expandtab (2)
- android_UI控件实现 (0)
- android_viewfinderview (1)
- android-Popup (1)
- Android—TextView (0)
- Android-network (1)
- android_share (1)
- Android_pulldownview (0)
- android-Switch (1)
- android_actionbar (1)
- Android_scrollview (1)
- android_util (9)
- android-sparseArray (1)
- android_Adapter (1)
- Android—DatePicker (2)
- kjframeforandroid (1)
- DragSortListView (1)
- Afinal (1)
- Android-StaggeredGrid (1)
- SmoothProgressBar (1)
- ExplosionField (1)
- android-async-http (1)
- Android—circleindicator (1)
- android—stepsview (1)
- android—spanny (1)
- Android-ViewPager (2)
- android—pull layout (1)
- Android—time (1)
- PullToDismissPager (1)
- android—chart (1)
- android—pullzoomview (1)
- listviewfilter (1)
- andrAndroid-GIF (1)
- android—ListView,StickyScrollView (1)
- gradle (1)
- android—fragment (1)
- Android--Glide (2)
- Android - SharedPreferences (1)
- Android_imageview (2)
- dialog弹出框 (2)
- android-recyclerview (2)
- Android-Badger (1)
- android_dialog (2)
- android—RecyclerView (4)
- android TextView (1)
- android—topbar (1)
- android—轮播图效果 (1)
- Android—imageView (2)
- androidAndroid—button (1)
- 视频教程 (1)
- kotlin学习 (1)
- Android—tag (1)
- android—view (1)
- TabLayout (1)
- android-webView (1)
- rich-text (1)
- swiper标点样式 (1)
- image (1)
- ExpandableTextView (1)
- viewPager (0)
最新评论
-
龙哥IT:
把这些东西,放在一起,自己用的时候方便而已,不用到处找了
Android权限Uri.parse的几种用法 -
YURANUS_:
干货 哈哈哈
Android权限Uri.parse的几种用法 -
narutolzj:
楼主,AppUtils类是自定义的吗,找不到~~
获取安装的应用 -
black_smart:
...
Android权限Uri.parse的几种用法 -
liu_zheng:
博主 我想把文字换成图片 要怎么修改呢??
用linearLayout代替ListView
http://qsyz2002.blog.163.com/blog/static/7216669201143115331662/
其中日期标题部分视图布局:
view sourceprint?1 <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”fill_parent” android:layout_height=”10dip” android:background=”@drawable/section_background”> <TextView android:id=”@+id/section_title” android:layout_width=”fill_parent” android:layout_height=”match_parent” /> </LinearLayout>
带图片的条目布局部分:
<?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=”horizontal” > <ImageView android:id=”@+id/image” android:src=”@drawable/p” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> <TextView android:id=”@+id/title” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> </LinearLayout>
问题在于,如何在ListView中既有标题条目又有内容条目。
这里用到了设计模式中的Iterator模式。在java代码中示例有Iterator,可以迭代ArrayList,HashSet等不同的数据结构对象。
ListElement是接口:
package com.easymorse.listview.customer; import android.content.Context; import android.view.LayoutInflater; import android.view.View; public interface ListElement { public int getLayoutId(); public boolean isClickable(); public View getViewForListElement(LayoutInflater layoutInflater, Context context, View view); }
其中:
- getLayoutId()返回布局的值;
- isClickable()返回是否可点击;
- getViewForListElement()返回视图对象。
这个接口有两个实现:
- SectionListElement,用于实现标题条目;
- ContentListElement,用于实现内容条目。
见SectionListElement代码:
package com.easymorse.listview.customer; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.widget.LinearLayout; import android.widget.TextView; public class SectionListElement implements ListElement { private String text; public void setText(String text) { this.text = text; } @Override public int getLayoutId() { return R.layout.section; } @Override public boolean isClickable() { return false; } @Override public View getViewForListElement(LayoutInflater layoutInflater, Context context, View view) { LinearLayout layout = (LinearLayout) layoutInflater.inflate(getLayoutId(), null); TextView textView=(TextView) layout.findViewById(R.id.section_title); textView.setText(text); return layout; } }
见ContentListElement代码:
public class ContentListElement implements ListElement { private String title; public void setTitle(String title) { this.title = title; } @Override public int getLayoutId() { return R.layout.item; } @Override public View getViewForListElement(LayoutInflater layoutInflater, Context context, View view) { LinearLayout layout = (LinearLayout) layoutInflater.inflate( getLayoutId(), null); TextView textView = (TextView) layout.findViewById(R.id.title); textView.setText(title); return layout;
ListView需要ListAdapter的实现。在这里是直接集成BaseAdapter来实现的。用于交给ListView生成出列表。代码:
public class CustomerListAdapter extends BaseAdapter { private Context context; protected ArrayList<ListElement> resultList; private LayoutInflater layoutInflater; public CustomerListAdapter(Context context) { super(); this.context = context; this.layoutInflater = (LayoutInflater) context .getSystemService(“layout_inflater”); this.resultList = new ArrayList<ListElement>(); } @Override public int getCount() { return this.resultList.size(); } @Override public Object getItem(int position) { return this.resultList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View view, ViewGroup parent) { return this.resultList.get(position).getViewForListElement( layoutInflater, context, view); } public void addList(List<ListElement> elements) { this.resultList.addAll(elements); } @Override public boolean isEnabled(int position) { return this.resultList.get(position).isClickable(); } public void addSectionHeaderItem(String text) { SectionListElement element = new SectionListElement(); element.setText(text); this.resultList.add(element); } }
在Activity中创建CustomerListAdapter以及设置它的代码部分:
CustomerListAdapter adapter = new CustomerListAdapter(this); adapter.addSectionHeaderItem(“2002-3-1″); ArrayList<ListElement> elements = new ArrayList<ListElement>(); for (int i = 0; i < 5; i++) { ContentListElement element = new ContentListElement(); element.setTitle(“哈利波特第” + (i+1) + “集”); elements.add(element); } adapter.addList(elements); adapter.addSectionHeaderItem(“2002-2-2″); elements = new ArrayList<ListElement>(); for (int i = 0; i < 3; i++) { ContentListElement element = new ContentListElement(); element.setTitle(“指环王第” + (i+1) + “集”); elements.add(element); } adapter.addList(elements); this.setListAdapter(adapter);
这里ListActivity,还需要注意两件事情,Activity要继承ListActivity。另外,在layout中:
ListView的id要用系统自带的
发表评论
-
不同的操作,加载更多样式不同
2018-06-06 16:24 496添加包: implementation 'com.scw ... -
列表滚动底部,自动显示发回顶部按钮
2017-08-08 16:00 508AutoScrollBackLayout 在ListVie ... -
ExpandableLinearLayout列表展开和收起功能
2017-07-17 16:10 888之前接触过几个类似的功能,展开和收起,都是自己在适配器里面 ... -
WaterDropListView实现ios7仿IOS“雨滴”拖拽的下拉刷新
2016-05-28 15:13 460WaterDropListView实现ios7下拉刷新和翻页 ... -
Listview列表滑动删除效果
2015-03-05 15:43 1434package com.ryg.slideview; ... -
点击实现 图标 晃动效果
2014-03-26 10:26 864定义Animation Animation sha ... -
下拉刷新功能
2012-03-15 15:08 2129参照别人的代码,然后根据需求,拉过来的,很实用 1。首 ... -
ListView动态分页的时候,定位滚动条的位置
2011-11-23 11:25 48071。找到每一页的最后一条数据的位置 public void ... -
用linearLayout代替ListView
2011-11-02 12:18 12255因为一个界面上面的内容太多,下面ListView查看不到,想在 ... -
ListView-自动加载数据一点代码
2011-10-26 15:37 1645private List<Map<String, ... -
设置ListView每个item点击背景图片设置
2011-10-26 15:31 7655利用itemview,fire,line来 ... -
ExpandableListView基本需要
2011-10-26 15:26 1314展开 int groupCount = viewAdapte ... -
ListView--BaseAdapter
2011-10-09 17:07 896自定义Adapter继承BaseAdapter http:// ... -
ListView的动态加载-很简单的Demo
2011-10-08 10:01 7959ListView的动态加载,想必大家在网上都看过很多资料了。我 ...
相关推荐
该资源主要源于:http://www.android100.org/html/201305/15/2606.html
自定义ListView实现下拉刷新+加载更多功能Demo
ListView选中多个
android--ListView实现带标题栏效果(附源码)
实现一个Activity中多个ListView的整体上下滑动效果,每个ListView分别使用一个自定义的适配器
ListView列表中播放多个视频
listview 上有两个按钮 一个编辑文本 一个按钮为加 一个为减 编辑文本为只读 触发按钮事件 文本相应变化
actionBar+searchView+listView实现搜索;包含两个例子;分别展示了android实现搜索的两种不同方法
HorizontalScrollListView上个有个标题,里面有个ListView.左边还有个listView;多个列表及滚动视图实现联动,即:滚动中间的HorizontalScrollListView,左边,里边,上边的三个列表均有联动,就像图表一样。还不明白...
Android实战运用中可能有很多地方会用到ListView,更为复杂的是每个item嵌入了多个Edittext,给我们造成很大的困扰,本资源就是为大家提供一个简单的参考,希望对大家有所帮助
用simpleAdapter实现listview的item,更改item对应的布局就可以仿淘宝实现多个listview上下滑动
listview实现三级列表listview实现三级列表
ListView加载多个布局
将不同的内容用标题表示出来,展示在一个listview中
listview加载多个布局文件,代码分主Activity和适配器两部分,布局文件就不写了,相信大家会写
如何在一个布局里面共享多个listview
Android完美解决listview中多个edittext显示混乱问题,内含源码及apk文件
1.标题栏用RadioGroup,RadioButton来实现,下面的展示由viewpager和fragment组合实现,内容为listView。 2.可以点击radiobutton 改变选中状态,进行切换fragment。 3.由于用了viewpager,也可以左右滑动。 4.代码...
android一个界面多个listview,android一个界面多个listview,
listview 实现隐藏显示headerview