adapter

Deserializing ImmutableList using Gson

一世执手 提交于 2019-11-28 10:02:12
I'm using quite a few immutable collections and I'm curious how to deserialize them using Gson. As nobody answered and I've found the solution myself, I'm simplifying the question and presenting my own answer. I had two problems: How to write a single Deserializer working for all ImmutableList<XXX> ? How to register it for all ImmutableList<XXX> ? Update: There's https://github.com/acebaggins/gson-serializers which covers many guava collections: ImmutableList ImmutableSet ImmutableSortedSet ImmutableMap ImmutableSortedMap How to write a single Deserializer working for all ImmutableList? The

ListView adapter data change without ListView being notified

女生的网名这么多〃 提交于 2019-11-28 09:26:45
I've written a ListActivity that has a custom list adapter. The list is being updated from a ContentProvider when onCreate is run. I also have a service that gets started when I run the app and it first updates the ContentProvider, then sends a Broadcast that the content has been updated. My ListActivity receives the broadcast and tries to update my ListView. My problem is, I'm getting intermittent errors about the ListView adapter data changing without the ListView being notified. I call the notifyDataSetChanged() method on my list adapter right after I update it. What it seems like is

RecycleView adapter data show wrong when scrolling too fast

末鹿安然 提交于 2019-11-28 09:19:17
问题 I have a custom Recycle View adapter that list my items. in each Item I check database and draw some circles with colors. when I scroll listview very fast every drawed data ( not title and texts) show wrongs! how I can manage dynamic View creation without showing wrong data?! @Override public void onBindViewHolder(final ItemViewHolder itemViewHolder, int i) { itemViewHolder.date.setText(items.get(i).getData()); // set the title itemViewHolder.relative_layout_tag_place.addView

What is the right way to communicate from a custom View to the Activity in which it resides?

寵の児 提交于 2019-11-28 09:13:13
I have a custom View class that extends Spinner. I'm trying to figure out what the correct way to talk to the Activity that it's embedded in is, when the user makes a selection. I see that the OnItemSelected listener gets a reference to the Adapter, but I'm not clear on whether or not I should be using this adapter and walking up its parent chain somehow, or if I should just talk directly to the context (for some reason that doesn't feel safe, even though I can't think of a way in which it might fail, offhand). Tal Kanel the right way to do that, is to "listen" to your custom view by exposing

学习Lowdb小型本地JSON数据库

霸气de小男生 提交于 2019-11-28 08:53:11
Lowdb是轻量化的基于Node的JSON文件数据库。对于构建不依赖服务器的小型项目,使用LowDB存储和管理数据是非常不错的选择。 一:lowdb 使用及安装 在项目中的根目录安装 lowdb 命令如下: npm install --save-dev lowdb lowdb是基于 lodash 构建的,因此我们可以使用任何 lodash 强大的函数。并且我们可以串联使用。 下面我们的目录结构比如是如下: |--- lowdb | |--- node_modules | |--- app.js | |--- package.json 然后我们在app.js 添加如下代码: const low = require('lowdb'); const FileSync = require('lowdb/adapters/FileSync'); const adapter = new FileSync('./db.json'); const db = low(adapter); db.defaults({posts: [], user: {}, count: 0 }).write(); 如上保存后,我们在命令行中执行 node app.js 后,会在我们的项目中的根目录下新建一个叫 db.json 文件,该文件代码变成如下所示: { "posts": [], "user": {},

ClassCastException with ListView when executing notifyDataSetChanged

大城市里の小女人 提交于 2019-11-28 06:44:35
I have added a view to the header of listVivew, View TopSearch = (View) View.inflate(this, R.layout.search, null); lv.addHeaderView(TopSearch, null, false); And everything is fine until I try to execute (when data changes) adapter.notifyDataSetChanged(); That always crash my application giving me following error: > java.lang.ClassCastException: android.widget.HeaderViewListAdapter If I remove header view then there is no error. Any suggestions? Thanks. It seems that whenever you use header/footer views in a listview, your ListView gets wrapped with a HeaderViewListAdapter. You can fix this

适配器模式

笑着哭i 提交于 2019-11-28 05:11:55
转载自https://www.cnblogs.com/V1haoge/p/6479118.html 适配器就是一种适配中间件,它存在于不匹配的二者之间,用于连接二者,将不匹配变得匹配,简单点理解就是平常所见的转接头,转换器之类的存在。   适配器模式有两种:类适配器、对象适配器、接口适配器   前二者在实现上有些许区别,作用一样,第三个接口适配器差别较大。 1、类适配器模式:   原理:通过继承来实现适配器功能。   当我们要访问的接口A中没有我们想要的方法 ,却在另一个接口B中发现了合适的方法,我们又不能改变访问接口A,在这种情况下,我们可以定义一个适配器p来进行中转,这个适配器p要实现我们访问的接口A,这样我们就能继续访问当前接口A中的方法(虽然它目前不是我们的菜),然后再继承接口B的实现类BB,这样我们可以在适配器P中访问接口B的方法了,这时我们在适配器P中的接口A方法中直接引用BB中的合适方法,这样就完成了一个简单的类适配器。   详见下方实例:我们以ps2与usb的转接为例 ps2接口:Ps2 1 public interface Ps2 { 2 void isPs2(); 3 } USB接口:Usb 1 public interface Usb { 2 void isUsb(); 3 } USB接口实现类:Usber 1 public class Usber

Android: ListView with complex data model

时光总嘲笑我的痴心妄想 提交于 2019-11-28 04:35:58
问题 I'd like to map an Array of "complex" data to a ListView. In a very simplified form my data model would look like something like this: class ListPlacesValues { String idObject; String name; String city; String country; ArrayList<String> classification; double distance_quantity; DistanceUnit distance_unit; [...more stuff ...] } I know that I can convert my complex data into a HashList and then just use a SimpleAdapter: SimpleAdapter mAdapter = new SimpleAdapter( this, hashList, R.layout.places

Remove all items from RecyclerView

杀马特。学长 韩版系。学妹 提交于 2019-11-28 04:29:47
I am trying to remove all the elements from my RecyclerView in my onRestart method so the items don't get loaded twice: @Override protected void onRestart() { super.onRestart(); // first clear the recycler view so items are not populated twice for (int i = 0; i < recyclerAdapter.getSize(); i++) { recyclerAdapter.delete(i); } // then reload the data PostCall doPostCall = new PostCall(); // my AsyncTask... doPostCall.execute(); } But for some reason the delete method I created in the adapter is not functioning properly: in RecyclerAdapter.java: public void delete(int position){ myList.remove

ListView with Horizontal ScrollView

只谈情不闲聊 提交于 2019-11-28 04:04:02
问题 I am trying to make a listview which consists of a horizontal scrollview as each one of the rows. I want the elements to be lined up vertically so the view would become scrollable if there are more then a certain amount of items. However it comes out looking like this. I am inflating the following xml single_row.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:background="#FFFFFF"