adapter

设计模式之Memento(备忘机制)

无人久伴 提交于 2019-12-05 20:35:16
1、创建型模式 JDK1.5枚举Singleton 单例模式 AbstractFactory 工厂方法模式 简单工厂模式 Builder Prototype 2、结构型 java设计模式—Adapter模式 从Decorator,Adapter模式看Java的IO库 Bridge Composite Decorator 外观模式 Facade Pattern 享元模式 Flyweight Pattern 代理模式 3、行为型 职责链模式 Chain of Responsibility Pattern Java之命令模式(Command Pattern) Iterator ( JAVA迭代器与迭代模式 ) 调停者模式(Mediator) 设计模式之Memento(备忘机制) Observer State Strategy Visitor 原文作者: duanxz 原文地址:https://www.cnblogs.com/duanxz/p/3633475.html 来源: https://www.cnblogs.com/wjqhuaxia/p/11945718.html

Void value as return parameter

前提是你 提交于 2019-12-05 16:07:39
问题 I have this interface: public interface Command<T> { T execute(String... args); } it works fine for most uses. But when I try to model a command that have only side effects (e.g. without return value) I'm tempted to write: public class SideEffectCommand implements Command<Void> { @Override public Void execute(String... args) { return null; // null is fine? } } Is this a common problem? Are there best practices to model Commands with and without return value? I've tried with this adapter but I

Make sure the content of your adapter is not modified from a background thread, but only from the UI thread

狂风中的少年 提交于 2019-12-05 16:00:39
I've an Activity with a EditText (named "filtro") and a ListView (named "list_view"). When the user inserts text, the adapter should be refresh; if i change text many times, comes a crash followed by the message "Make sure the content of your adapter is not modified from a background thread, but only from the UI thread" listener : filtro.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) { Log.d(TAG, "onTextChanged(" + cs + ")"); adapter.getFilter().filter(cs); } @Override public void beforeTextChanged(CharSequence arg0

How to get height of view inside adapter for creating sized bitmap?

偶尔善良 提交于 2019-12-05 15:56:14
I use custom CursorAdapter with custom items. I need height of view to resize Bitmap from assets folder and set this resized bitmap to ImegeView in list item; @Override public void bindView(View view, final Context context, final Cursor cursor) { final ViewHolder holder = (ViewHolder) view.getTag(); final int imgCol = cursor.getColumnIndex(TableOdelice.COLUMN_URL); int titleCol = cursor.getColumnIndex(TableOdelice.COLUMN_TITRE); final int themeCol = cursor.getColumnIndex(TableOdelice.COLUMN_THEME); String tempPath = getPath(cursor.getString(themeCol), cursor.getString(imgCol)); final String

Android之Adapter用法总结

我与影子孤独终老i 提交于 2019-12-05 13:12:45
Android 之 Adapter 用法总结 1. 概念 Adapter 是连接后端数据和前端显示的适配器接口,是数据和 UI ( View )之间一个重要的纽带。在常见的 View(List View,Grid View) 等地方都需要用到 Adapter 。如下图直观的表达了 Data 、 Adapter 、 View 三者的关系: Android 中所有的 Adapter 一览: 由图可以看到在 Android 中与 Adapter 有关的所有接口、类的完整层级图。在我们使用过程中可以根据自己的需求实现接口或者继承类进行一定的扩展。比较常用的有 Base Adapter , Impleader , Adapter , Counteradaptation 等。 BaseAdapter是一个抽象类,继承它需要实现较多的方法,所以也就具有较高的灵活性; ArrayAdapter支持泛型操作, 最为简单,只能展示一行字。 SimpleAdapter有最好的扩充性,可以自定义出各种效果。 SimpleCursorAdapter 可以适用于简单的纯文字型ListView,它需要Cursor的字段和UI的id对应起来。如需要实现更复杂的UI也可以重写其他方法。可以认为是 SimpleAdapter对数据库的简单结合,可以方便地把数据库的内容以列表的形式展示出来。 2.应用案例 1)

Android中ListView分类

寵の児 提交于 2019-12-05 13:10:03
1. 引言 在Android开发过程中往往有这样的需求,将ListView中的内容按年,月,日进行分类显示,要实现这样的效果我们可能有很多种方法, 如:多ListView拼合,自定义ListView组件等,下面介绍一种比较简单,而且实现结构清晰的实现方式,效果图及实现如下。 2. 效果图 3. 功能实现 (1) 主布局(main.xml)实现: [java] view plain copy <?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 = "fill_parent" > <ListView android:id = "@+id/categoryList" android:layout_width = "fill_parent" android:layout_height = "fill_parent" /> </LinearLayout> (2) 主Activity实现: [java] view plain copy

How to call notifyDataSetChanged() from a generic Adapter

雨燕双飞 提交于 2019-12-05 12:05:35
An OnItemClickListener for a ListView has the following method: @Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) I'd like to have the adapter behind the ListView refresh, and I believe this is done through the use of: BaseAdapter.notifyDataSetChanged() How do I use the parent parameter in the onItemClick method to do this? So far I've tried: parent.getAdapter().notifyDataSetChanged(); This throws an error because the object returned is of class HeaderViewListAdapter , which for reasons unknown isn't a subclass of BaseAdapter . AFAIK, there isn't any

Create library to override operator*() of iterator - risk dangling pointer

走远了吗. 提交于 2019-12-05 11:39:40
问题 I am trying to create my own boost::adaptors::transformed. Here is the related boost code. Here is its usage (modified from a SO answer by LogicStuff):- C funcPointer(B& b){ //"funcPointer" is function convert from "B" to "C" return instance-of-C } MyArray<B> test; //<-- any type, must already have begin() & end() for(C c : test | boost::adaptor::transformed(funcPointer)) { //... something .... } The result will be the same as :- for(auto b : test) { C c = funcPointer(b); //... something ...

Android ListView adapter with two ArrayLists

耗尽温柔 提交于 2019-12-05 10:50:55
In our chat app we want to use cool new Library SQLBrite to update chat on database changes. Since our chat has endless scrolling, and chat room can have very big list of messages, we want to split ArrayList supplied to Chat ListView adapter into two lists. Check graphic for the idea. We want to set point in database above which, old messages will be queried by normal SQLite queries. And below that point we want set SQLBrite, that will bring us fresh messages added to database. Each part should populate its corresponding ArrayList. And two arrayLists should be combined in one adapter. My

How I can filter my DataTable by Column Value?

淺唱寂寞╮ 提交于 2019-12-05 07:55:15
I have a question about DataTable . I retrieve a DataTable from the database, and one of these columns contains either a 1 or a 0. Now I want to retrieve only the rows with a 1 value of 1 in that column. The name of the column is ACTIVATE . Here is my DataTable : DataTable table = new DataTable(TABLE); //How can I filter here so ACTIVATE == 1? adapter.Fill(table); connection.Open(); selectcommand.ExecuteReader(); return table; Via SQL (preferred) SELECT * FROM dbo.Table WHERE ACTIVATE = 1 Via Linq-To-Datatable (in memory): DataTable tblFiltered = table.AsEnumerable() .Where(r => r.Field<int>(