当前位置:  编程技术>移动开发
本页文章导读:
    ▪本地通报(二)        本地通知(二) 以前写过一篇文章:本地通知,本文是基于此基础的一个简单的例子。   localnotificationAppDelegate.h   #import <UIKit/UIKit.h> @class localnotificationViewController; @interface localnotifi.........
    ▪ 被TranslateAnimation弄晕了        被TranslateAnimation搞晕了。 bottomFrameAnimationOut = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.ABSOLUTE, -205, TranslateAnimation.ABSOLUTE, 0);原来这里的每.........
    ▪ Dialog调用dismiss方法出现错误解决办法       Dialog调用dismiss方法出现异常解决方法 本文原创,转载请保留原文地址: http://maosidiaoxian.iteye.com/blog/1547445在使用Dialog时,调用dismiss方法,有时会出现异常:java.lang.IllegalArgumentException: View .........

[1]本地通报(二)
    来源: 互联网  发布时间: 2014-02-18
本地通知(二)

以前写过一篇文章:本地通知,本文是基于此基础的一个简单的例子。

 

localnotificationAppDelegate.h

 

#import <UIKit/UIKit.h>

@class localnotificationViewController;

@interface localnotificationAppDelegate : NSObject <UIApplicationDelegate> {
	UIWindow *window;
	localnotificationViewController *viewController;
}

@property(nonatomic, retain) IBOutlet UIWindow *window;
@property(nonatomic, retain) IBOutlet localnotificationViewController *viewController;

@end

 

localnotificationAppDelegate.m

 

#import "localnotificationAppDelegate.h"
#import "localnotificationViewController.h"

@implementation localnotificationAppDelegate

@synthesize window;
@synthesize viewController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
	application.applicationIconBadgeNumber = 0;
	[self.window addSubview:viewController.view];
	[self.window makeKeyAndVisible];
	
	return YES;
}

#pragma mark -
#pragma mark Memory management

- (void)dealloc {
	[viewController release];
	[window release];
	[super dealloc];
}

@end

 

 localnotificationViewController.h

 

#import <UIKit/UIKit.h>

@interface localnotificationViewController : UIViewController {
	IBOutlet UILabel *myLable1;
	IBOutlet UILabel *myLable2;
	IBOutlet UILabel *myLable3;
}

@property(nonatomic, retain) UILabel *myLable1;
@property(nonatomic, retain) UILabel *myLable2;
@property(nonatomic, retain) UILabel *myLable3;

- (IBAction)onChangeValue:(id)sender;

@end

 

 localnotificationViewController.m

 

#import "localnotificationViewController.h"

@implementation localnotificationViewController

@synthesize myLable1, myLable2, myLable3;

- (void)viewDidLoad {
	[super viewDidLoad];
	[[UIApplication sharedApplication] cancelAllLocalNotifications];
}

- (void)viewDidUnload {
	self.myLable1 = nil;
	self.myLable2 = nil;
	self.myLable3 = nil;
}

- (void)dealloc {
	[myLable1 release], myLable1 = nil;
	[myLable2 release], myLable2 = nil;
	[myLable3 release], myLable3 = nil;
	[super dealloc];
}

#pragma mark -
#pragma mark onChageValue

- (IBAction)onChangeValue:(id)sender {
	UISwitch *switchBtn = (UISwitch *)sender;
	if (switchBtn.on) {
		UILocalNotification *notification = [[UILocalNotification alloc] init]; 
		NSDate *now = [NSDate date];  
		notification.timeZone = [NSTimeZone defaultTimeZone]; 
		notification.repeatInterval = NSDayCalendarUnit;
		notification.applicationIconBadgeNumber = 1;
		notification.alertAction = NSLocalizedString(@"显示", nil);
		switch (switchBtn.tag) {
			case 0:
			{
				notification.fireDate = [now dateByAddingTimeInterval:5];
				notification.alertBody = self.myLable1.text; 
			}
				break;
			case 1:
			{
				notification.fireDate = [now dateByAddingTimeInterval:10];
				notification.alertBody = self.myLable2.text; 
			}
				break;
			case 2:
			{
				notification.fireDate = [now dateByAddingTimeInterval:15];
				notification.alertBody = self.myLable3.text; 
			}
				break;
			default:
				break;
		}
		[notification setSoundName:UILocalNotificationDefaultSoundName];
		NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
												 [NSString stringWithFormat:@"%d", switchBtn.tag], @"key", nil];
		[notification setUserInfo:dic];
		[[UIApplication sharedApplication] scheduleLocalNotification:notification];
	} else {
		NSArray *array = [[UIApplication sharedApplication] scheduledLocalNotifications];
		for (int i = 0; i < [array count]; i++) {
			UILocalNotification	*myUILocalNotification = [array objectAtIndex:i];
			if ([[[myUILocalNotification userInfo] objectForKey:@"key"] intValue] == switchBtn.tag) {
				[[UIApplication sharedApplication] cancelLocalNotification:myUILocalNotification];
			}
		}
	}
}

@end

 

效果图:


 


    
[2] 被TranslateAnimation弄晕了
    来源: 互联网  发布时间: 2014-02-18
被TranslateAnimation搞晕了。
bottomFrameAnimationOut = new TranslateAnimation(TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.RELATIVE_TO_SELF, 0f, TranslateAnimation.ABSOLUTE, -205, TranslateAnimation.ABSOLUTE, 0);


原来这里的每一个参数都是相对于当前view的值。

如果你想点击一个按钮然后把一个view从一个地方移到另一个地方的话。

        mailboxHeaderBar.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) mailboxHeaderBar.getLayoutParams();
                int bottomMargin = layoutParams.bottomMargin;
                if (bottomMargin < 0) {
                    mailboxHeaderBar.startAnimation(bottomFrameAnimationIn);
                    layoutParams.bottomMargin = 0;
                }else{
                    mailboxHeaderBar.startAnimation(bottomFrameAnimationOut);
                    layoutParams.bottomMargin = -205;
                }
                mailboxHeaderBar.setLayoutParams(layoutParams);
            }
        });


其实在你startAnimation的时候View的位置已经变了。 Animation里面的参数值是需要相对你移动view之后的值。 有点晕  fuck

    
[3] Dialog调用dismiss方法出现错误解决办法
    来源: 互联网  发布时间: 2014-02-18
Dialog调用dismiss方法出现异常解决方法
本文原创,转载请保留原文地址: http://maosidiaoxian.iteye.com/blog/1547445

在使用Dialog时,调用dismiss方法,有时会出现异常:java.lang.IllegalArgumentException: View not attached to window manager

出现这个异常的原因可能是,在dismiss对话框的时候,它所在的activity因为一些原因已经先退出了,所以会出现这个异常。
目前我认为最好的解决方法是,使用Activity里面封装好的showDialog(int id)和dismissDialog(int id)方法。
使用示例代码如下(代码取自我的一个项目,去掉与本主题无关内容,如果有小的错误,请自行调试):
/*
 * @(#)SearchActivity.java		       Project:lol
 * Date:2012-4-29
 *
 * Copyright (c) 2011 CFuture09, Institute of Software, 
 * Guangdong Ocean University, Zhanjiang, GuangDong, China.
 * All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.sinaapp.msdxblog.android.lol.activity;

import android.app.Activity;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.FrameLayout.LayoutParams;
import android.widget.LinearLayout;

import com.sinaapp.msdxblog.android.lol.R;
import com.sinaapp.msdxblog.androidkit.thread.HandlerFactory;

/**
 * @author Geek_Soledad (66704238@51uc.com)
 */
public abstract class WebViewActivity extends Activity {

	protected WebView mSearchWV;
	protected Context mContext;
	private static final int PROGRESS_ID = 1;

	/**
	 * 返回需要加载的URL地址。
	 * 
	 * @return 需要加载的URL地址。
	 */
	protected abstract String getHomeUrl();

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mContext = this;
		mSearchWV = new WebView(mContext);
		mSearchWV.getSettings().setJavaScriptEnabled(true);
		mSearchWV.setWebViewClient(new WebViewClient() {

			public boolean shouldOverrideUrlLoading(WebView view, String url) {
				view.loadUrl(/blog_article/url/index.html);
				return true;
			}

			@Override
			public void onPageStarted(WebView view, String url, Bitmap favicon) {
				super.onPageStarted(view, url, favicon);
				showDialog(PROGRESS_ID);
			}

			@Override
			public void onPageFinished(WebView view, String url) {
				super.onPageFinished(view, url);
				dismissDialog(PROGRESS_ID);
			}
		});
		addContentView(mSearchWV, new FrameLayout.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));

		mSearchWV.loadUrl(getHomeUrl());
	}

	@Override
	protected Dialog onCreateDialog(int id) {
		if (id == PROGRESS_ID) {
			return ProgressDialog.show(mContext, null,
					mContext.getString(R.string.loading));
		}
		return super.onCreateDialog(id);
	}
}

    
最新技术文章:
▪Android开发之登录验证实例教程
▪Android开发之注册登录方法示例
▪Android获取手机SIM卡运营商信息的方法
▪Android实现将已发送的短信写入短信数据库的...
▪Android发送短信功能代码
▪Android根据电话号码获得联系人头像实例代码
▪Android中GPS定位的用法实例
▪Android实现退出时关闭所有Activity的方法
▪Android实现文件的分割和组装
▪Android录音应用实例教程
▪Android双击返回键退出程序的实现方法
▪Android实现侦听电池状态显示、电量及充电动...
▪Android获取当前已连接的wifi信号强度的方法
▪Android实现动态显示或隐藏密码输入框的内容
▪根据USER-AGENT判断手机类型并跳转到相应的app...
▪Android Touch事件分发过程详解
▪Android中实现为TextView添加多个可点击的文本
▪Android程序设计之AIDL实例详解
▪Android显式启动与隐式启动Activity的区别介绍
▪Android按钮单击事件的四种常用写法总结
▪Android消息处理机制Looper和Handler详解
▪Android实现Back功能代码片段总结
▪Android实用的代码片段 常用代码总结
▪Android实现弹出键盘的方法
▪Android中通过view方式获取当前Activity的屏幕截...
▪Android提高之自定义Menu(TabMenu)实现方法
▪Android提高之多方向抽屉实现方法
▪Android提高之MediaPlayer播放网络音频的实现方法...
▪Android提高之MediaPlayer播放网络视频的实现方法...
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

©2012-2021,,E-mail:www_#163.com(请将#改为@)

浙ICP备11055608号-3