Android常用函数库

/*
	 * function:传入参数创建自定义的显示Dialog
	 * title:dialog的消息体
	 * bt1:按钮上的text
	 * bt2:按钮上的text
	 * author:dy
	 * time:12-08-14
	 */
	private Dialog createMyDialog(String title,String bt1,String bt2) {
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
		dialogBuilder.setMessage(title)
					 .setCancelable(false)
					 .setPositiveButton(bt1, new DialogInterface.OnClickListener() {
						
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							DialogActivity.this.finish();
						}
					})
					.setNegativeButton(bt2, new DialogInterface.OnClickListener() {
						
						public void onClick(DialogInterface dialog, int which) {
							// TODO Auto-generated method stub
							dialog.cancel();
						}
					});
	
		return dialogBuilder.create();
	}
/*
	 * function:自定义notification函数
	 * icon:图标索引
	 * original:消息名称
	 * notificationTitile:具体消息的Titile
	 * notificationText:具体消息的内容
	 * author:dy
	 * time:12-08-14
	 */
	private void dyNotification(int icon, String original,String notificationTitle, String notificationText) {
		//定义ID
		final int ID = 1;
		//创建Intent对象和PendingIntent对象
		Intent intent = new Intent(this,aNotificationActivity.class);
		PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, 0);
		//获取MOtificationManager对象
		NotificationManager nm = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
		//创建Notification对象
		Notification n = new Notification(icon,original,System.currentTimeMillis());
		//设置消息事件
		n.setLatestEventInfo(getApplicationContext(), notificationTitle, notificationText, contentIntent);
		//将notification添加到NotificationManager中
		nm.notify(ID, n);
	}

/*
	 * function:弹出的消息对话框中的内容是list显示的
	 * title:dialog的title
	 * items:一个字符数组,其中的每一项就被显示在list中
	 * author:dy
	 * time:12-08-14
	 * 
	 */
	private Dialog createListDialog(String title,final CharSequence[] items) {
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
		dialogBuilder.setTitle(title);
		dialogBuilder.setItems(items, new DialogInterface.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int item) {
				// TODO Auto-generated method stub
				//Toast.makeText(getApplication(), items[item], Toast.LENGTH_LONG).show();
				//to dong somethings
			}
		});
	
		return dialogBuilder.create();
	}

	/*
	 * function:弹出的消息对话框中的内容是一checkBoxes的形式显示的
	 * title:dialog的title
	 * items:一个字符数组,其中的每一项就被显示在checkBoxes选项中
	 * author:dy
	 * time:12-08-14
	 * 
	 */
	private Dialog createCheckBoxesDialog(String title,final CharSequence[] items) {
		AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
		dialogBuilder.setTitle(title);
		dialogBuilder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
			
			public void onClick(DialogInterface dialog, int item) {
				// TODO Auto-generated method stub
				//Toast.makeText(getApplication(), items[item], Toast.LENGTH_LONG).show();
				//to do somethings
			}
		});
	
		return dialogBuilder.create();
	}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值