当前位置:  编程技术>移动开发
本页文章导读:
    ▪时间演算之Dates        时间运算之Dates Creating Date Objects NSTimeInterval secondsPerDay = 24 * 60 * 60; NSDate *tomorrow = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay]; NSDate *yesterday = [NSDate dateWithTimeIntervalSinceNow:-secondsPe.........
    ▪ 实例HelloDatePicker        范例HelloDatePicker Android docs中的范例,简单翻译整理如下。 --------------------------------------------1、创建新项目,名称HelloDatePicker; 2、修改res/layout/main.xml,内容如下: <?xml version="1.0" encoding.........
    ▪ 用java回布局activity(贴个代码),动态生成页面       用java来布局activity(贴个代码),动态生成页面, 虽然功能上实现了但是布局上不够漂亮,很丑啊,考虑用网页的方式来实现,思路如果可以借鉴请借鉴。作用主要是动态生成一些页面控件,.........

[1]时间演算之Dates
    来源: 互联网  发布时间: 2014-02-18
时间运算之Dates
Creating Date Objects
NSTimeInterval secondsPerDay = 24 * 60 * 60;
NSDate *tomorrow = [NSDate
            dateWithTimeIntervalSinceNow:secondsPerDay];
NSDate *yesterday = [NSDate
            dateWithTimeIntervalSinceNow:-secondsPerDay];

 

 To get new date objects with date-and-time values adjusted from existing date objects, use addTimeInterval:.

 

NSTimeInterval secondsPerDay = 24 * 60 * 60;
NSDate *today = [NSDate date];
NSDate *tomorrow, yesterday;
 
tomorrow = [today addTimeInterval:secondsPerDay];
yesterday = [today addTimeInterval:-secondsPerDay];

 

 

 

Basic Date Calculations

 

 

To compare dates, use the isEqualToDate:, compare:, laterDate:, and earlierDate: methods. These methods perform exact comparisons, which means they will detect subsecond differences between dates. You might want to compare dates with a less fine granularity. For example, you might want to consider two dates equal if they are within a minute of each other. If this is the case, use timeIntervalSinceDate: to compare the two dates or use a Gregorian date instead (NSCalendarDate in Objective-C, NSGregorianDate in Java). The following Objective-C code shows how to use timeIntervalSinceDate: to see if two dates are within one minute (60 seconds) of each other.

 

if (fabs([date2 timeIntervalSinceDate:date1]) < 60) ...

 


    
[2] 实例HelloDatePicker
    来源: 互联网  发布时间: 2014-02-18
范例HelloDatePicker
Android docs中的范例,简单翻译整理如下。
--------------------------------------------
1、创建新项目,名称HelloDatePicker;

2、修改res/layout/main.xml,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical">
    <TextView android:id="@+id/dateDisplay"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text=""/>
    <Button android:id="@+id/pickDate"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Change the date"/>
</LinearLayout>


3、修改HelloDatePicker.java,增加成员变量定义,代码如下:
    private TextView mDateDisplay;
    private Button mPickDate;
    private int mYear;
    private int mMonth;
    private int mDay;

    static final int DATE_DIALOG_ID = 0;


4、修改HelloDatePicker.java的onCreate方法,内容如下:
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // capture our View elements
        mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
        mPickDate = (Button) findViewById(R.id.pickDate);

        // add a click listener to the button
        mPickDate.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DATE_DIALOG_ID);
            }
        });

        // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);

        // display the current date (this method is below)
        updateDisplay();
    }


5、修改HelloDatePicker.java增加updateDisplay方法,内容如下:
    // updates the date in the TextView
    private void updateDisplay() {
        mDateDisplay.setText(
            new StringBuilder()
                    // Month is 0 based so add 1
                    .append(mMonth + 1).append("-")
                    .append(mDay).append("-")
                    .append(mYear).append(" "));
    }


6、修改HelloDatePicker.java增加日期选择对话框,内容如下:
    // the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {

                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
                    updateDisplay();
                }
            };


7、修改HelloDatePicker.java增加onCreateDialog方法,内容如下:
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this,
                    mDateSetListener,
                    mYear, mMonth, mDay);
    }
    return null;
}


8、运行项目,即可看到运行效果,如下图所示:


    
[3] 用java回布局activity(贴个代码),动态生成页面
    来源: 互联网  发布时间: 2014-02-18
用java来布局activity(贴个代码),动态生成页面,
虽然功能上实现了但是布局上不够漂亮,很丑啊,考虑用网页的方式来实现,思路如果可以借鉴请借鉴。作用主要是动态生成一些页面控件,大家有好的思路也可以提供给我啊。或者修改这段代码,layout.xml方式暂时不考虑

typeindex = 0;
		adindex = 0;
		for(int i = 0; i <list.size();i++){
			final int tempint = i;
			String flag = list.get(i).getFlg();
			RelativeLayout rel = new RelativeLayout(Act.this);
			rel.setGravity(Gravity.CENTER_HORIZONTAL);
			RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
			if("1".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("类 型:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				RelativeLayout rel2 = new RelativeLayout(Act.this);
				RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
				
				final EditText tt = new EditText(Act.this);
				tt.setBackgroundDrawable(getResources().getDrawable(R.drawable.select_edit));
				tt.setEnabled(false);
				tt.setSingleLine();
				tt.setId(2);
				ImageView image1 = new ImageView(Act.this);
				image1.setImageDrawable(getResources().getDrawable(R.drawable.select));
				image1.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						List<SelectBean> selectList = list.get(tempint).getList();
						final String[] names = new String[selectList.size()];
						final String[] ids = new String[selectList.size()];
						for(int i=0;i<selectList.size();i++){
							names[i] = selectList.get(i).getName();
							ids[i] = selectList.get(i).getId();
						}
						
						dialog =	 new AlertDialog.Builder(Act.this)
		                .setTitle("请选择类型")
		                .setSingleChoiceItems(names, typeindex, new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {
								typeindex = whichButton;
		                    }
		                }).setPositiveButton("确 定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                    	tt.setText(names[typeindex]);
		                    	typeStr = "&"+list.get(tempint).getArg_name()+"="+ids[typeindex];
		                    }
		               })
		               .setNegativeButton("取 消", new DialogInterface.OnClickListener() {
		            	   public void onClick(DialogInterface dialog, int id) {
		            		 
		                   }
		               }).create();
						dialog.show();
					}
				});
				rel2.addView(tt);
				lp2.addRule(RelativeLayout.RIGHT_OF, tt.getId());
				rel2.addView(image1,lp2);
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				
				rel.addView(t);
				rel.addView(rel2,lp);
			}else if("2".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("前 缀:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				RelativeLayout rel2 = new RelativeLayout(Act.this);
				RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
					ViewGroup.LayoutParams.WRAP_CONTENT);
				
				final EditText tt = new EditText(Act.this);
				tt.setBackgroundDrawable(getResources().getDrawable(R.drawable.select_edit));
				tt.setEnabled(false);
				tt.setSingleLine();
				tt.setId(2);
				ImageView image1 = new ImageView(Act.this);
				image1.setImageDrawable(getResources().getDrawable(R.drawable.select));
				image1.setOnClickListener(new OnClickListener() {
					
					@Override
					public void onClick(View v) {
						List<SelectBean> selectList1 = list.get(tempint).getList();
						final String[] namess = new String[selectList1.size()];
						final String[] idss = new String[selectList1.size()];
						for(int i=0;i<selectList1.size();i++){
							namess[i] = selectList1.get(i).getName();
							idss[i] = selectList1.get(i).getId();
						}
						
						dialog =	 new AlertDialog.Builder(Act.this)
		                .setTitle("前 缀:")
		                .setSingleChoiceItems(namess, adindex, new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int whichButton) {
		                    	adindex = whichButton;
		                    }
		                }).setPositiveButton("确 定", new DialogInterface.OnClickListener() {
		                    public void onClick(DialogInterface dialog, int id) {
		                    	tt.setText(namess[adindex]);
		                    	adStrx = namess[adindex];
		                    	adStr = "&"+list.get(tempint).getArg_name()+"="+idss[adindex];
		                    }
		               })
		               .setNegativeButton("取 消", new DialogInterface.OnClickListener() {
		            	   public void onClick(DialogInterface dialog, int id) {
		            	
		                   }
		               }).create();
						dialog.show();
					}
				});
				rel2.addView(tt);
				lp2.addRule(RelativeLayout.RIGHT_OF, tt.getId());
				rel2.addView(image1,lp2);
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				
				rel.addView(t);
				rel.addView(rel2,lp);
			}else if("3".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("号 :");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt3 = new EditText(Act.this);
				tt3.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt3,lp);
			}else if("4".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText(" 号:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt4 = new EditText(Act.this);
				tt4.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt4,lp);
			}else if("5".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("代 码:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt5 = new EditText(Act.this);
				tt5.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt5,lp);
			}else if("6".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("编 号:");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt6 = new EditText(Act.this);
				tt6.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt6,lp);
			}else if("9".equals(flag)){
				TextView t = new TextView(Act.this);
				t.setText("号: ");
				t.setTextColor(R.color.define_blue);
				t.setTextSize(18);
				t.setId(1);
				tt9 = new EditText(Act.this);
				tt9.setBackgroundDrawable(getResources().getDrawable(R.drawable.text));
				lp.addRule(RelativeLayout.RIGHT_OF,t.getId());
				rel.addView(t);
				rel.addView(tt9,lp);
			}
			
			linear.addView(rel);
		}
	}



    
最新技术文章:
▪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播放网络音频的实现方法...
HTML教程 iis7站长之家
▪Android提高之手游转电视游戏的模拟操控
 


站内导航:


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

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

浙ICP备11055608号-3