adapter

适配器模式(Adapter Pattern)

≡放荡痞女 提交于 2019-12-24 10:40:46
定义: 适配器模式,即定义一个包装类,用于包装不兼容接口的对象 解决的问题: 原本由于接口不兼容而不能一起工作的那些类可以在一起工作 类别: 类的适配器模式和 对象的适配器模式 uml类图: 模式组成 目标接口(Target) :客户所期待的接口。目标可以是具体的或抽象的类,也可以是接口 需要适配的类(Adaptee) :需要适配的类或适配者类 适配器(Adapter) :通过包装一个需要适配的对象,把原接口转换成目标接口 优点: 更好的复用性 系统需要使用现有的类,而此类的接口不符合系统的需要。那么通过适配器模式就可以让这些功能得到更好的复用。 透明、简单 客户端可以调用同一接口,因而对客户端来说是透明的。这样做更简单 & 更直接 更好的扩展性 在实现适配器功能的时候,可以调用自己开发的功能,从而自然地扩展系统的功能。 解耦性 将目标类和适配者类解耦,通过引入一个适配器类重用现有的适配者类,而无需修改原有代码 符合开放-关闭原则 同一个适配器可以把适配者类和它的子类都适配到目标接口;可以为不同的目标接口实现不同的适配器,而不需要修改待适配类 缺点: 过多的使用适配器,会让系统非常零乱,不易整体进行把握 举个栗子 定义目标接口 interface Target { public void request(); } 定义需要适配的类 class Adaptee { public

Powershell - how to create network adapter (loopback)?

﹥>﹥吖頭↗ 提交于 2019-12-24 08:34:41
问题 I want to create a loopback network adapter with powershell. I can get an adapter using code like this. $networkAdapter = Get-WMIObject win32_NetworkAdapter | where{$_.ServiceName -eq 'msloop'} However, I cannot seem to find how to create an adapter. The only thing I found uses devcon.exe .\devcon.exe -r install $env:windir\Inf\Netloop.inf *MSLOOP | Out-Null This is going to be for a windows 7 box and I didn't want to have to install some other package just to do it. If devcon is required

GridView with custom ImageAdapter doesn't update after dataset changes

守給你的承諾、 提交于 2019-12-24 07:55:34
问题 I'm implementing a gallery of images with support for multiple item selection. The main layout is a GridView which uses a custom Adapter . Every displayed item is a combination ImageView + CheckBox . If several checkboxes are checked I want to uncheck them all simply by touching any image in the GridView . I'm calling notifyDataSetChanged() for implementing this functionality. Unfortunately this "uncheck all" feature doesn't work. I'm still a newbie so probably there is something basic that I

android adaptor row hiding

↘锁芯ラ 提交于 2019-12-24 05:54:10
问题 In arrayAdptor we use following code: final LayoutInflater inflater = activity.getLayoutInflater(); row = (LinearLayoutCustom) inflater.inflate(R.layout.row, null); final TextView label = (TextView) row.findViewById(R.id.title); label.setText(position + "" + items[position]); return row; Now suppose some value are null (for example at position 2 , items[2] = null ) so i dont want to show it in row. i want to hide it. if i use row.setVisibility(View.GONE) it leaves a blank space at this row

Android “attempted to access a cursor after it has been closed”

非 Y 不嫁゛ 提交于 2019-12-24 03:44:09
问题 I'm trying to adapt the HelloGridView example so that I can show image thumbnails of images stored on the SD instead of images in the res/drawable. The idea is to create a list with the images first in the ImageView.initialize() function and the use it pretty much exactly as in the example. I'm having trouble with my cursor, first I tried to have it as private in the Imageview.initialize() function (it's only commented away so you can see where I had it) since to me it seems like it is only

Android “attempted to access a cursor after it has been closed”

空扰寡人 提交于 2019-12-24 03:44:06
问题 I'm trying to adapt the HelloGridView example so that I can show image thumbnails of images stored on the SD instead of images in the res/drawable. The idea is to create a list with the images first in the ImageView.initialize() function and the use it pretty much exactly as in the example. I'm having trouble with my cursor, first I tried to have it as private in the Imageview.initialize() function (it's only commented away so you can see where I had it) since to me it seems like it is only

Oracle Protocol Adapter Error

非 Y 不嫁゛ 提交于 2019-12-24 03:24:38
问题 HI, I've just installed Oracle 10 g Express Edition on to my laptop. The platform is Windows XP SP3. Installation went normally. BUt when I try to get connected to the Oracle database via SqlPlus I get "TNS Protocol adapter error".My laptop is on the network.I'd installed the same database on to a Windows Server 2003 and it works fine. What could the problem be? 回答1: I presume this is ORA-12560: TNS:protocol adapter error . The Oracle documentation describes it as a generic TNS error, but

Change Background on a specific row based on a condition in Custom Adapter

大城市里の小女人 提交于 2019-12-24 02:33:44
问题 I'm trying to change the background color of a row based upon a flag received from the database on a remote server. In my code, I create an ArrayList called disable that holds all of the positions that were flagged. I want to match what is in disable's list to the positions in my ListView. I have researched several postings and none of them explicitly show how to do this. I've pieced together what I found and put it in the custom adapter below. From what I understand public int

Data repeating in android list view

社会主义新天地 提交于 2019-12-24 02:12:22
问题 I have a list view whose adapter is in a different class in a different package. Now I have to get the data from database then I set Adapter for my list view using this data. So I have created an ArryList and pass this in the constructor of Adapter while seeting it for the list view. But the problem is that the data is repeating. eg.- there are 12 distinct Strings in the arraylist but what I get is -first five elements in order and after that the same five are being repeated. The count of

Android中ListView的各种显示效果

淺唱寂寞╮ 提交于 2019-12-23 20:58:30
在android应用开发中,ListView是使用频率非常高的一个组件,基本上稍微复杂点的布局都会用到它,利用它可以让你的界面美观,有层次 。ListView可以用来作为数据显示的容器,也可以作为界面的布局。学习ListView需要关注的内容大概有三点:显示、数据适配器以及各种 事件的监听器。内容有点多,这里先只讲如何让ListView达到你想要的显示效果。 一、普通的ListView 普通的ListView是指每一个item只显示一条文本数据,程序运行效果图如下: 代码: protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.layout_listview_simple); //取得ListView实例 ListView lvwSimple = (ListView)findViewById(R.id.lvw_simple); //要在ListView中显示的数据集合 String items[] = new String[] {"item1", "item2", "item3", "item4", "item5"}; /