viewholder

第十次作业

為{幸葍}努か 提交于 2019-12-04 09:29:08
<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:textColor="#000" android:textSize="20sp"

第十一个作业

萝らか妹 提交于 2019-12-04 08:31:10
MainActivity.java 代码: public class MainActivity extends ActionBarActivity { private EditText etName, etPrice, etNumber; private ListView listView; private String name, price, number; private MyHelper myHelper; private SQLiteDatabase db; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); myHelper = new MyHelper(this); init(); } public void click(View v) { ContentValues values; // 创建ContentValues对象 switch (v.getId()) { case R.id.button1: name = etPrice.getText().toString(); price = etName.getText().toString()

Day11_11

廉价感情. 提交于 2019-12-04 06:18:16
<?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 5.0+(RecycleView、CardView、Palette)

两盒软妹~` 提交于 2019-12-04 05:19:42
Android L 开发者预览支持库提供两个新的Widgets,RecyclerView和CardView。使用这两个Widgets可以显示复杂的Listview和卡片布局,这两个Widgets默认使用Material design。 RecyclerView RecyclerView是一个更高级柔性版本的Listview,RecyclerView是一个能包含很多视图的容器,它能完美的处理循环和滚动。在item动态变化的Listview使用RecyclerView。 RecyclerView使用很简单,因为它提供了: 1、定位item的布局管理器 2、常见的item操作默认动画 你能够灵活的为RecyclerView自定义布局管理器和动画。 使用RecyclerView,必须使用指定一个adapter、定义一个布局管理器。创建adapter必须继承自RecyclerView.Adapter。实施的细节需要看数据类型和需要的视图。 RecyclerView widget RecyclerView 提供了 LayoutManager,RecylerView 不负责子 View 的布局 目前提供了 LinearLayoutManager(显示垂直或水平滚动列表中的条目。) GridLayoutManager(在一个网格显示项) StaggeredGridLayoutManager

作业十

喜欢而已 提交于 2019-12-04 04:22:09
<?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

RecyclerView的刷新分页

百般思念 提交于 2019-12-03 18:55:20
在开发中常常使用到刷新分页,这里实现一个 RecyclerView 的简单的刷新分页操作。 RecyclerView的使用请参考: RecyclerView的简单使用 RecyclerView的 Item 的单击事件请参考: RecyclerView的 Item 的单击事件 实现思路 加载更多数据使用到 RecyclerView 加载多种布局,根据 ViewType 判断加载数据 Item 还是加载 FooterItem ; 通过线程模拟加载数据; 为 RecyclerView 添加 addOnScrollListener 事件来监听用户的滑动操作; 根据用户滑动状态以及具体情况开始加载数据 通知数据更新; 如何获得 firstVisibleItemPosition 为了能够在数据加载中动态判断什么时候加载数据,需要知道屏幕上显示的第一个可见的 Item 的位置,当然了这里使用的是布局管理器是 LinearLayoutManager ,这样查找屏幕上第一个可见的 Item 就显得容易多了,下面介绍一些 LinearLayoutManager 的四个方法: findFirstVisibleItemPosition() 获得屏幕上第一个可见 Item 的 position,只要该 Item 有一部分可见,那么返回的 position 就是该Item 的 position。

Android开发操作案例分享!

一笑奈何 提交于 2019-12-03 18:54:58
Android开发操作案例分享! Android LRecyclerView 操作案例分享-实现下拉刷新、滑动到底部自动加载,一直想抽空写下这个开源项目 www.lampbrother.net ,但是各种原因没有抽时间,今天还是趁着工作间隙写下了这篇博客,与大家分享。 简介 LRecyclerView是支持addHeaderView、 addFooterView、下拉刷新、分页加载数据的RecyclerView。 它对 RecyclerView 控件进行了拓展,给RecyclerView增加HeaderView、FooterView,并且不需要对你的Adapter做任何修改。 主要功能 下拉刷新、滑动到底部自动加载下页数据; 可以方便添加Header和Footer; 头部下拉样式可以自定义; 具备item点击和长按事件。 网络错误加载失败点击Footer重新请求数据; 可以动态为FooterView赋予不同状态(加载中、加载失败、滑到最底等)。 感谢 如果我比别人看得远些,那是因为我站在巨人们的肩上。 (牛顿) 本开源控件是基于 HeaderAndFooterRecyclerView 开源项目而来,在原基础上进行了扩充。在此感谢兄弟连教育(www.lampbrother.net)的分享 Gradle Step 1. 在你的根build.gradle文件中增加JitPack仓库依赖。

Android ViewHolder Background Color

匿名 (未验证) 提交于 2019-12-03 10:10:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am creating an Android application that contains a RecyclerView with a nested CardView. I need to alternate every other Card to a different color. I am using @Override to override the onBindViewHolder(ViewHolder vh, int pos) method. I need to change the background color from that method (I assume), but there are no methods to set the background color of a ViewHolder! I'm sorry for my noobie-ness, I'm learning Android development now. -Ben EDIT: Code: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate

onClickListener in RecyclerView adapter?

匿名 (未验证) 提交于 2019-12-03 09:19:38
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I want to set up an onClickListener within my RecyclerView adapter so I can easily refer to the other views to retrieve their tags. Is it possible to set up an onClickListener in a RecyclerView adapter? How would I do it? Would it affect performance? Here is my RecyclerView adapter: public class PostRecyclerAdapter extends RecyclerView . Adapter < PostRecyclerAdapter . ViewHolder > { private Context context ; private List < Post > mDataset ; public static class ViewHolder extends RecyclerView . ViewHolder implements View .

Absolute position in BaseAdapter of GrivView

匿名 (未验证) 提交于 2019-12-03 08:52:47
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm trying to write BaseAdapter to my GrivView but in public View getView ( int position , View convertView , ViewGroup parent ) { ... } the position while rendering next elements is: visible elements --------------- | 1 2 3 | | 4 5 6 | <--- screen | 7 8 9 | --------------- nonvisible elements | 1 2 3 | <-- below visible area | 4 5 6 | where real is: visible elements --------------- | 1 2 3 | | 4 5 6 | | 7 8 9 | --------------- nonvisible elements | 10 11 12 | | 13 14 15 | I'm aware it's correct behaviour (it counts only visible