viewholder

RecyclerView的通用适配器,和滚动时不加载图片的封装

我只是一个虾纸丫 提交于 2019-12-06 22:41:28
很早之前写过一篇讲ListView的万能适配器的方案 通用Adapter与ListView滚动时不加载图片的封装 ,可以让你在写ListView的Adapter时只关注对控件设置内容,而不需要再去考虑ViewHolder、控件初始化、以及实现BaseAdapter的其他三个必须实现的函数。 对于RecyclerView我们需要使用RecyclerAdapter,使用方式与ListViewAdapter类似,具体代码大家可以在网上搜索,这里就只教大家使用封装后的简洁RecyclerAdapter了。 ##核心代码 首先我们来看一部分核心代码: public abstract class BaseRecyclerAdapter<T> extends RecyclerView.Adapter<RecyclerHolder> { public BaseRecyclerAdapter(RecyclerView v, Collection<T> datas, int itemLayoutId) { //... } /** * Recycler适配器填充方法 * * @param holder viewholder * @param item javabean * @param isScrolling RecyclerView是否正在滚动 */ public abstract void

第十次作业

杀马特。学长 韩版系。学妹 提交于 2019-12-06 19:34:28
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E6E6E6" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="42dp" android:orientation="horizontal"> <ImageView android:id="@+id/imageView6" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginLeft="1dp" android:layout_marginTop="11dp" app

Android Selector

拟墨画扇 提交于 2019-12-06 07:53:06
Selector的应用: http://www.cnblogs.com/loulijun/archive/2012/04/15/2450312.html 使用selector修改TextView中字体的颜色: http://blog.csdn.net/dinglin_87/article/details/7885806 2.这个是另一种思路 http://blog.csdn.net/lo5sea/article/details/6647680 3.viewholder高亮错乱 http://blog.sina.com.cn/s/blog_7040845601017ak5.html 关键代码如下: final MyAdapter myAdapter=new MyAdapter(this, data); setListAdapter(myAdapter); getListView().setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { myAdapter.setSelectItem(position); myAdapter

Java-Android SD卡路径问题以及如何获取SDCard内存大小

主宰稳场 提交于 2019-12-05 19:29:19
在研究拍照后突破的存储路径的问题,开始存储路径写死为: private String folder = "/sdcard/DCIM/Camera/"(SD卡上拍照程序的图片存储路径); 后来发现这样写虽然一般不会出错,但不是很好,因为不同相机,可能路径会出问题。较好的方法是通过Environment 来获取路径,最后给出一个例子,教你怎样获取SDCard 的内存,显示出来告诉用户。讲述的内容如下: 0、获取sd卡路径。 1、讲述 Environment 类。 2、讲述 StatFs 类。 3、完整例子读取 SDCard 内存 0、获取sd卡路径 方法一: private String folder = "/sdcard/DCIM/Camera/"(SD卡上拍照程序的图片存储路径); //写死绝对路径,不赞成使用 方法二: public String getSDPath(){ File sdDir = null; boolean sdCardExist = Environment.getExternalStorageState() .equals(Android.os.Environment.MEDIA_MOUNTED); //判断sd卡是否存在 if (sdCardExist) { sdDir = Environment.getExternalStorageDirectory();

第十次作业

落花浮王杯 提交于 2019-12-05 15:31:06
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E6E6E6" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:background="@android:color/white" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="名称:" android

多宫格抽奖

这一生的挚爱 提交于 2019-12-05 07:02:48
网上大多的多宫格抽奖都是自定义view,如果view的布局不一样而且太多的话容易出现oom,不好管理 结合RecyclerView实现多宫格抽奖 效果图如下 满足所有矩形多宫格抽奖 9宫格 16宫格 25宫格 也可以不是正方形 比如 4行5列 acitivity的xml <android.support.v7.widget.RecyclerView android:id="@+id/recycleView" android:layout_width="match_parent" android:layout_height="match_parent" />recyclerView的adapter下面LuckRecyclerViewAdapter /** * Created by taq on 2018/7/3. */import android.animation.Animator;import android.animation.AnimatorListenerAdapter;import android.animation.ValueAnimator;import android.content.Context;import android.support.annotation.NonNull;import android.support.v4.content

作业10

橙三吉。 提交于 2019-12-04 20:29:03
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#E6E6E6" android:orientation="vertical" android:padding="10dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:background="@android:color/white" android:orientation="horizontal"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="名称:" android

Android第四十天

跟風遠走 提交于 2019-12-04 16:18:15
1、ListView分页加载 <1>分页的作用 (1)避免一次性加载过多内容时,造成内存溢出; (2)可以增强用户体验。 <2>实现思路 (1)当滚动到最后一条的时候,加载新数据; (2)适配器的数据源要进行累加:listDatas.addAll(list) (3)数据发生变化时,适配器及时通知:adapter.notifyDataSetChanged() (4)判断是否滚到了最后一行 if (firstVisibleItem + visibleItemCount == totalItemCount ) { isBottom = true; } <3>实例步骤 (1)模拟1000条数据,以分页方式显示; (2)使用BaseAdapter自定义适配器显示数据; (3)在ListView下方增加“显示更多”按钮以实现加载下一页数据; (4)ListView.setOnScrollListener()方法设置滚动事件监听器; (5)通过滚动事件监听器判断是否滚动到最底部,若在底部则显示“显示更多“按钮; (6)点击“显示更多”按钮,根据当前的页码与一页显示的记录数,加载数据; (7)将加载的数据追加到适配器的数据源中 2、AdapterView.OnItemClickListener 列表项点击事件监听器:onItemClick(AdapterView<?> parent, View

第02讲集合类和列表类控件

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 16:08:23
集合 有了数组为什么还要集合: 数组是固定长度的,集合长度可变(因此,适应场景不同) 同时存储一对一关系的数据 方便增删改查 不能添加重复数据(如set中) Collection Map 接口 HashMap List Queue Set ArrayList LinkedList HashSet 类 Collection存储类的对象,Map存储键值对。 List和Queue存储的对象是有序的,允许重复的,可以为null;Set中存储的对象是无序的,不允许重复的,只能有一个为null。 ArrayList l ArrayList底层是由数组实现的 l 可以动态增长 l 列表尾部添加或删除元素效率高(在中间插入或删除元素需要移动后面的元素) l 更适合查找或更新元素 l 元素可以为NULL add() 插入元素 size() 查看元素个数,遍历输出元素 remove() 移除元素 (remove(“dd”)只会移除一个) 用removeAll(Collection)可以删除所有 HashSet l Set是元素无序,并且不可以重复的集合,称为集 l HashSet是Set的一个重要的实现类 l HashSet只允许有一个Null值 l 具有良好的存取及查找性能 Iterator(迭代器) Iterator接口可以以统一的方式对各种集合元素进行遍历 hasNext(

ViewSwitcher的功能与用法

孤街醉人 提交于 2019-12-04 15:16:31
ViewSwitcher代表了视图切换组件,它本身继承了FramLayout,因此可以将多个View层叠在一起,每次只显示一个组件。当程序控制从一个View切换到另一个View时,ViewSwitcher支持指定动画效果。 为了给ViewSwitcher添加多个组件,一般通过调用ViewSwitcher的setFactory(ViewSwitcher.ViewFactory)方法为之设置ViewFactory,并由该ViewFactory为之创建View即可。 实例:仿Android系统的Launcher界面 Android早期版本的Launcher界面是上下滚动的,新版Android的Launcher界面已经实现了分屏、左右滚动,本例就是通过ViewSwitcher来实现Android的分屏、左右滚动效果。 为了实现该效果,程序主界面考虑使用ViewSwitcher来组合多个GridView,每个GridView代表一个屏幕应用程序,GridView中每个单元格显示一个应用程序的图标和程序名。 布局文件如下 <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res