Storyboard类介绍
原文地址:最新Xcode 4.3.2 下使用Storyboard和ARC开发iPhone4程序 03——Storyboard类及使用作者:浪友dans
一、Storyboard类介绍
Storyboard是你可以用来定义用户界面的一种新的方式,像xib。与xib不同的是它可以同时管理多个ViewController,而且可以在Storyboard中配置ViewController 之间的跳转关系。
如果主窗口只有一个view controller是作为story board的第一个界面,就需要勾选上 Initial Scene。
story board是xcode4.2新增的一个特性,它将原有工程中的所有xib文件集成在一起,用拖拽的方式建立起两个viewController之间的跳转关系,使得整个程序的UI跳转逻辑清楚明了。使用storyboard后,界面相关的代码编写将更少。
简单说一个storyboard是个什么东西。storyboard引入了两个概念:
scene: 一个场景,由一个viewController和相关的xib表示
segue: ['seiɡwei] n. 继续,持续。用于连接scenes,segue有多种类型,包括:
Push, Modal, Popover and more
segue 也负责传递数据和返回数据。
整个程序的界面转换就是在scene之间切换。界面跳转关系,比如按哪个键跳到哪个界面,由segue来描述。segue也可以带数据,以便做数据传递。据说苹果的这种设计方案是抄的 Adobe的Flash,具体不得而知。
1、UIStoryboard类
此类继承于NSObject,共有三个方法,一个类方法,两个实例方法
1)得到一个StoryBoard Object对象:类方法
+ (UIStoryboard *)storyboardWithName:(NSString *)name bundle:(NSBundle*)storyboard
BundleOrNil;
// 也可以通过一个在storyboard中有scene的viewController中用self.storyBoard得到自己所在的storyboard对象。
2)接口
- (id)instantiateInitialViewController;
// 返回第一个界面(根视图所在界面),每个storyboard都必须有一个入口界面,特别是程序的主storyboard的第一个界面,就是程序的主界面。
- (id)instantiateViewControllerWithIdentifier:(NSString *)identifier;
// storyboard中相应标识对应的界面。如果identifier不存在或者为nil,引发异常。
2、UIStoryboardSegue类,同样此类继承于NSObject
两个界面之间的转换,转换之前调用当前view controller的 prepareForSegue:sender: 函数(这里可以处理一些数据赋值之类).可以通过生成子类来自定义转换动画.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
}
1)属性
@property(nonatomic, readonly) id destinationViewController // (read-only)
@property (nonatomic, readonly) NSString *identifier // (read-only)
@property(nonatomic, readonly) id sourceViewController // (read-only)
2)初始化,此类公有一个实例方法
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController*)source destination:(UIViewController *)destination;
3、UIStoryboardPopoverSegue类。此类继承于UIStoryboardSegue : NSObject
此类只有一个属性:
@property(nonatomic, retain, readonly) UIPopoverController*popoverController;
4、动画
- (void)perform; // 子类重写来自定义转换动画
@property(nonatomic, retain, readonly) UIPopoverController*popoverController;
二、Storyboard使用
如果你是创建新项目,Xcode模版可以提供一个配置好的Storyboard供你使用。对于其它的应用,使用Storyboard的过程如下:
1、配置应用程序Info.plist文件
· 添加UIMainStoryboardFile ,值为storyboard的文件名。
· 删除原来的NSMainNibFile
2、像以前创建xib文件一样创建一个storyboard文件
3、配置 storyboard中的viewController
三、Storyboard的创建
你可以用InterfaceBuilder 去为你的应用程序创建一个Stroyboard,一般来说一个应用使用一个 Storyboard就够了,但是如果你想创建多个也是可以的,只要你愿意。一个 Stroyboard应该至少含有一个ViewController。
在iPhone中,对于每一个在Storyboard的ViewController都管理着一个scene,每个scene又管理着screen上的东东,但对于iPad来说,多个scene可以同时呈现在一个screen上。你可以从library中拖拽viewController到你的Storyboard上。
当你想关联两个viewController时,你可以按着control键,用鼠标从一个ViewController中的button,table view cell…拖拽连接到另一个你想跳转到的ViewController,这样就创建了一个segue,不要忘记设置identifier哦。
四、 Scene之间的数据传递
当你从当前 scene中触发一个segue的时候,系统会自动调用prepareForSegue:sender:这个方法。如果你想从一个界面切换到里另一个界面的时候传递数据,你应该override这个方法。
五、ViewController之间的跳转
如果在 Storyboard中,要实现当前的 ViewController和要跳转到另一个ViewController。分两种情况:
1、连接场景segue存在。如果在 Storyboard中当前的 ViewController和要跳转的ViewController之间的segue存在,则可以执行performSegueWithIdentifier:sender:这个方法实现跳转。
2、连接场景segue不存在。如果目标ViewController存在Storyboard中,但是没有segue。你可以通过UIStoryboard的instantiateViewControllerWithIdentifier:这个方法获取到它,然后再用你想要的方式实现跳转,如:压栈。
3、如果目标ViewController不存在在 Storyboard中,那就先去创建它吧。
六、小结
根据上面的UIStoryBoard类知道,可以简单的把storyboard当成以前的nib文件使用,只不过他是一个合集,读取文件用另一种自己的函数就行了。正常的使用当然是灵活运用UIStoryboardSegue。它可以关系两个controller,关系一个controller中的控件到另一个controller中,还可以自定义一些动画。
使用GridView控件,却发现getView被重复调用,次数多达上百次,拖垮了系统,影响用户体验!
public View getView(int position, View convertView, ViewGroup parent) { Log.v(Tag, "<getView> position = " + position); ... return convertView; }
log信息:
10-12 10:43:09.880: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.890: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.890: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.900: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.910: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.910: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.920: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.920: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.940: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.940: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.940: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.940: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.950: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.960: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.970: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.970: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.980: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.980: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.990: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:09.990: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.000: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.010: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.010: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.090: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.110: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.110: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.120: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.120: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.140: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.140: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.140: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.150: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.160: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.160: V/GridViewAdapter(30785): <getView> position = 1 10-12 10:43:10.170: V/GridViewAdapter(30785): <getView> position = 2 10-12 10:43:10.200: V/GridViewAdapter(30785): <getView> position = 3 10-12 10:43:10.220: V/GridViewAdapter(30785): <getView> position = 4 10-12 10:43:10.360: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.380: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.410: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.420: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.450: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.460: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.470: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.480: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.530: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.530: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.540: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.540: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.570: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.570: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.580: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.590: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.620: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.620: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.630: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.640: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.661: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.661: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.661: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.661: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.791: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.791: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.801: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.811: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.831: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.831: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.851: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.871: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.961: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.961: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.961: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.961: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.991: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.991: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.991: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.991: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.021: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.021: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.021: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.021: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.041: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.051: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.061: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.061: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.071: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.081: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.081: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.091: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.101: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.111: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.111: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.111: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.131: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.131: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.131: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.141: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.161: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.171: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.181: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:11.181: V/GridViewAdapter(30785): <getView> position = 0
其中只有以下五条信息是正常的,其它都是多余。
10-12 10:43:10.160: V/GridViewAdapter(30785): <getView> position = 0 10-12 10:43:10.160: V/GridViewAdapter(30785): <getView> position = 1 10-12 10:43:10.170: V/GridViewAdapter(30785): <getView> position = 2 10-12 10:43:10.200: V/GridViewAdapter(30785): <getView> position = 3 10-12 10:43:10.220: V/GridViewAdapter(30785): <getView> position = 4
参考了网上很多的修改的方法,比如布局中高度属性wrap_content设为固定值或者fill_parent等,但都未起作用。也许遇到问题太特殊,只能自己想办法了!
虽然没有办法阻止系统重复调用getView,但是我们有办法让多余的getView什么都不做。如此这般就可以减轻系统负担,增加用户体验。
增加一个变量mCount来记录position = 0的次数,依据mCount的值来决定执行流程。
public View getView(int position, View convertView, ViewGroup parent) { Log.v(Tag, "<getView> position = " + position + " mCount = " + mCount); if (position == 0) { mCount++; } else { mCount = 0; } if (mCount > 1) { Log.v(Tag, "<getView> drop !!!"); return convertView; } ... return convertView; }
log信息
10-12 12:57:32.436: V/GridViewAdapter(32222): <getView> position = 0 mCount = 0 10-12 12:57:32.436: V/GridViewAdapter(32222): <getView> position = 0 mCount = 1 10-12 12:57:32.436: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.446: V/GridViewAdapter(32222): <getView> position = 0 mCount = 2 10-12 12:57:32.456: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.456: V/GridViewAdapter(32222): <getView> position = 0 mCount = 3 10-12 12:57:32.456: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> position = 0 mCount = 4 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> position = 0 mCount = 5 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> position = 0 mCount = 6 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> position = 0 mCount = 7 10-12 12:57:32.466: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> position = 0 mCount = 8 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> position = 0 mCount = 9 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> position = 0 mCount = 10 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> position = 0 mCount = 11 10-12 12:57:32.476: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> position = 0 mCount = 12 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> position = 0 mCount = 13 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> position = 0 mCount = 14 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> position = 0 mCount = 15 10-12 12:57:32.506: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.536: V/GridViewAdapter(32222): <getView> position = 0 mCount = 16 10-12 12:57:32.536: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.536: V/GridViewAdapter(32222): <getView> position = 0 mCount = 17 10-12 12:57:32.536: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.556: V/GridViewAdapter(32222): <getView> position = 0 mCount = 18 10-12 12:57:32.556: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.556: V/GridViewAdapter(32222): <getView> position = 0 mCount = 19 10-12 12:57:32.556: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.556: V/GridViewAdapter(32222): <getView> position = 0 mCount = 20 10-12 12:57:32.566: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.566: V/GridViewAdapter(32222): <getView> position = 0 mCount = 21 10-12 12:57:32.576: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.576: V/GridViewAdapter(32222): <getView> position = 0 mCount = 22 10-12 12:57:32.576: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.576: V/GridViewAdapter(32222): <getView> position = 0 mCount = 23 10-12 12:57:32.576: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.596: V/GridViewAdapter(32222): <getView> position = 0 mCount = 24 10-12 12:57:32.596: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.596: V/GridViewAdapter(32222): <getView> position = 0 mCount = 25 10-12 12:57:32.606: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.606: V/GridViewAdapter(32222): <getView> position = 0 mCount = 26 10-12 12:57:32.606: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.606: V/GridViewAdapter(32222): <getView> position = 0 mCount = 27 10-12 12:57:32.616: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.626: V/GridViewAdapter(32222): <getView> position = 0 mCount = 28 10-12 12:57:32.626: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.626: V/GridViewAdapter(32222): <getView> position = 0 mCount = 29 10-12 12:57:32.636: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.636: V/GridViewAdapter(32222): <getView> position = 0 mCount = 30 10-12 12:57:32.636: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.636: V/GridViewAdapter(32222): <getView> position = 0 mCount = 31 10-12 12:57:32.646: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.656: V/GridViewAdapter(32222): <getView> position = 0 mCount = 32 10-12 12:57:32.666: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.676: V/GridViewAdapter(32222): <getView> position = 1 mCount = 33 10-12 12:57:32.696: V/GridViewAdapter(32222): <getView> position = 2 mCount = 0 10-12 12:57:32.696: V/GridViewAdapter(32222): <getView> position = 3 mCount = 0 10-12 12:57:32.706: V/GridViewAdapter(32222): <getView> position = 4 mCount = 0 10-12 12:57:32.746: V/GridViewAdapter(32222): <getView> position = 0 mCount = 0 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> position = 0 mCount = 1 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> position = 0 mCount = 2 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> position = 0 mCount = 3 10-12 12:57:32.756: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> position = 0 mCount = 4 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> position = 0 mCount = 5 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> position = 0 mCount = 6 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.766: V/GridViewAdapter(32222): <getView> position = 0 mCount = 7 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> position = 0 mCount = 8 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> position = 0 mCount = 9 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> position = 0 mCount = 10 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> position = 0 mCount = 11 10-12 12:57:32.776: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> position = 0 mCount = 12 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> position = 0 mCount = 13 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> position = 0 mCount = 14 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> position = 0 mCount = 15 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.786: V/GridViewAdapter(32222): <getView> position = 0 mCount = 16 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> position = 0 mCount = 17 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> position = 0 mCount = 18 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> position = 0 mCount = 19 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> position = 0 mCount = 20 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> position = 0 mCount = 21 10-12 12:57:32.796: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> position = 0 mCount = 22 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> position = 0 mCount = 23 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> position = 0 mCount = 24 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.806: V/GridViewAdapter(32222): <getView> position = 0 mCount = 25 10-12 12:57:32.826: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.826: V/GridViewAdapter(32222): <getView> position = 0 mCount = 26 10-12 12:57:32.826: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.826: V/GridViewAdapter(32222): <getView> position = 0 mCount = 27 10-12 12:57:32.836: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.846: V/GridViewAdapter(32222): <getView> position = 0 mCount = 28 10-12 12:57:32.846: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.846: V/GridViewAdapter(32222): <getView> position = 0 mCount = 29 10-12 12:57:32.846: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.856: V/GridViewAdapter(32222): <getView> position = 0 mCount = 30 10-12 12:57:32.856: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.856: V/GridViewAdapter(32222): <getView> position = 0 mCount = 31 10-12 12:57:32.856: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> position = 0 mCount = 32 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> position = 0 mCount = 33 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> position = 0 mCount = 34 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> position = 0 mCount = 35 10-12 12:57:32.886: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> position = 0 mCount = 36 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> position = 0 mCount = 37 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> position = 0 mCount = 38 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> position = 0 mCount = 39 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.896: V/GridViewAdapter(32222): <getView> position = 0 mCount = 40 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> position = 0 mCount = 41 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> position = 0 mCount = 42 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> position = 0 mCount = 43 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> position = 0 mCount = 44 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> position = 0 mCount = 45 10-12 12:57:32.906: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> position = 0 mCount = 46 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> position = 0 mCount = 47 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> position = 0 mCount = 48 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> position = 0 mCount = 49 10-12 12:57:32.916: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.926: V/GridViewAdapter(32222): <getView> position = 0 mCount = 50 10-12 12:57:32.966: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.966: V/GridViewAdapter(32222): <getView> position = 0 mCount = 51 10-12 12:57:32.976: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> position = 0 mCount = 52 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> position = 0 mCount = 53 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> position = 0 mCount = 54 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> position = 0 mCount = 55 10-12 12:57:32.986: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:32.996: V/GridViewAdapter(32222): <getView> position = 0 mCount = 56 10-12 12:57:32.996: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> position = 0 mCount = 57 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> position = 0 mCount = 58 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> position = 0 mCount = 59 10-12 12:57:33.006: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> position = 0 mCount = 60 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> position = 0 mCount = 61 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> position = 0 mCount = 62 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> position = 0 mCount = 63 10-12 12:57:33.016: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 64 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 65 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 66 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 67 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 68 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 69 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.046: V/GridViewAdapter(32222): <getView> position = 0 mCount = 70 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> position = 0 mCount = 71 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> position = 0 mCount = 72 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> position = 0 mCount = 73 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> position = 0 mCount = 74 10-12 12:57:33.056: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> position = 0 mCount = 75 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> position = 0 mCount = 76 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> position = 0 mCount = 77 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> position = 0 mCount = 78 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> position = 0 mCount = 79 10-12 12:57:33.066: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> position = 0 mCount = 80 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> position = 0 mCount = 81 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> position = 0 mCount = 82 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> position = 0 mCount = 83 10-12 12:57:33.076: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> position = 0 mCount = 84 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> position = 0 mCount = 85 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> position = 0 mCount = 86 10-12 12:57:33.086: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> position = 0 mCount = 87 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> position = 0 mCount = 88 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> position = 0 mCount = 89 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> position = 0 mCount = 90 10-12 12:57:33.096: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> position = 0 mCount = 91 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> position = 0 mCount = 92 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> position = 0 mCount = 93 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> position = 0 mCount = 94 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> position = 0 mCount = 95 10-12 12:57:33.106: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> position = 0 mCount = 96 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> position = 0 mCount = 97 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> position = 0 mCount = 98 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> position = 0 mCount = 99 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.176: V/GridViewAdapter(32222): <getView> position = 0 mCount = 100 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> position = 0 mCount = 101 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> position = 0 mCount = 102 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> position = 0 mCount = 103 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.186: V/GridViewAdapter(32222): <getView> position = 0 mCount = 104 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> position = 0 mCount = 105 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> position = 0 mCount = 106 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> position = 0 mCount = 107 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> position = 0 mCount = 108 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> position = 0 mCount = 109 10-12 12:57:33.196: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> position = 0 mCount = 110 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> position = 0 mCount = 111 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> position = 0 mCount = 112 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> position = 0 mCount = 113 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.206: V/GridViewAdapter(32222): <getView> position = 0 mCount = 114 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> position = 0 mCount = 115 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> position = 0 mCount = 116 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> position = 0 mCount = 117 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> position = 0 mCount = 118 10-12 12:57:33.216: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> position = 0 mCount = 119 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> position = 0 mCount = 120 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> position = 0 mCount = 121 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> position = 0 mCount = 122 10-12 12:57:33.226: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> position = 0 mCount = 123 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> position = 0 mCount = 124 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> position = 0 mCount = 125 10-12 12:57:33.236: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.246: V/GridViewAdapter(32222): <getView> position = 0 mCount = 126 10-12 12:57:33.246: V/GridViewAdapter(32222): <getView> drop !!! 10-12 12:57:33.246: V/GridViewAdapter(32222): <getView> position = 0 mCount = 127 10-12 12:57:33.246: V/GridViewAdapter(32222): <getView> drop !!!
private void uploadFile()
{
String end = "\r\n";
String twoHyphens = "--";
String boundary = "*****";
try
{
URL url =new URL(/blog_article/actionUrl/index.html);
HttpURLConnection con=(HttpURLConnection)url.openConnection();
/* 允许Input、Output,不使用Cache */
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
/* 设定传送的method=POST */
con.setRequestMethod("POST");
/* setRequestProperty */
con.setRequestProperty("Connection", "Keep-Alive");
con.setRequestProperty("Charset", "UTF-8");
con.setRequestProperty("Content-Type",
"multipart/form-data;boundary="+boundary);
/* 设定DataOutputStream */
DataOutputStream ds =
new DataOutputStream(con.getOutputStream());
ds.writeBytes(twoHyphens + boundary + end);
ds.writeBytes("Content-Disposition: form-data; " +
"name=\"file1\";filename=\"" +
newName +"\"" + end);
ds.writeBytes(end);
/* 取得文件的FileInputStream */
FileInputStream fStream = new FileInputStream(uploadFile);
/* 设定每次写入1024bytes */
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int length = -1;
/* 从文件读取数据到缓冲区 */
while((length = fStream.read(buffer)) != -1)
{
/* 将数据写入DataOutputStream中 */
ds.write(buffer, 0, length);
}
ds.writeBytes(end);
ds.writeBytes(twoHyphens + boundary + twoHyphens + end);
/* close streams */
fStream.close();
ds.flush();
/* 取得Response内容 */
InputStream is = con.getInputStream();
int ch;
StringBuffer b =new StringBuffer();
while( ( ch = is.read() ) != -1 )
{
b.append( (char)ch );
}
/* 将Response显示于Dialog */
showDialog(b.toString().trim());
/* 关闭DataOutputStream */
ds.close();
}
catch(Exception e)
{
showDialog(""+e);
}
}
/* 在手机上打开文件的method */
private void openFile(File f)
{
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(android.content.Intent.ACTION_VIEW);
/* 调用getMIMEType()来取得MimeType */
String type = getMIMEType(f);
/* 设定intent的file与MimeType */
intent.setDataAndType(Uri.fromFile(f),type);
startActivity(intent);
}
/* 判断文件MimeType的method */
private String getMIMEType(File f)
{
String type="";
String fName=f.getName();
/* 取得扩展名 */
String end=fName.substring(fName.lastIndexOf(".")+1,fName.length()).toLowerCase();
/* 按扩展名的类型决定MimeType */
if(end.equals("m4a")||end.equals("mp3")||end.equals("mid")||end.equals("xmf")||end.equals("ogg")||end.equals("wav"))
{
type = "audio";
}
else if(end.equals("3gp")||end.equals("mp4"))
{
type = "video";
}
else if(end.equals("jpg")||end.equals("gif")||end.equals("png")||end.equals("jpeg")||end.equals("bmp"))
{
type = "image";
}
else if(end.equals("apk"))
{
/* android.permission.INSTALL_PACKAGES */
type = "application/vnd.android.package-archive";
}
else
{
type="*";
}
/*如果无法直接打开,就跳出软件清单给使用者选择 */
if(end.equals("apk"))
{
}
else
{
type += "/*";
}
return type;
}