×

preferencescreen layout 自定义

PreferenceScreen加载一个自定义布局layout,怎么设置监听?C#定时执行

admin admin 发表于2022-05-02 22:25:30 浏览126 评论0

抢沙发发表评论

PreferenceScreen加载一个自定义布局layout,怎么设置监听

应该说ListView里要加载两种不同的布局,而且不同的布局的响应事件也不一样。 你需要自定义一个MyAdapter extends BaseAdapter.然后在getView()方法里面加载不同的布局,为不同的布局定义不同的响应事件就好。

C#定时执行

启动程序的时候,就执行启动状态的任务? 用 Loaded 事件呀。每隔一段时间执行:建立一个 List《Timer》 型变量每添加一个任务,就:变量名.Add(new Timer())可用 变量名[索引] 的方法向数组一样访问。并设置属性 Interval, Enabled = True ,设定事件 变量名[索引].Tick+= 事件处理函数(这个函数要预先写好(不同种任务用不同函数,或用参数区分))定时执行 用一个Timer检查 DateTime.Now==定时的时间 就分情况执行不同任务(调用不同函数)。-------------------------------------------------补充:List《Type》是一个泛型的类。既然叫List,它有列表的作用,类似于数组,又优于数组:数组的元素个数必须是确定,而List《》不确定。而List可以与数组一样访问。既然是泛型,里面可以存任意同类型的变量。的尖括号中Type就是你想要的类型。-----------------------------------------//Form1.csusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace Example_Task{ public partial class Form1 : Form { List《Task》 lt = new List《Task》(); //任务列表 List《Timer》 cycleT=new List《Timer》(); //管理周期性任务 Timer timingT=new Timer(); //管理定时任务 enum condition { cycle, timing }; //任务执行条件 public enum tType { a, b, c }; //任务类型 tType type; bool Condition; public Form1() { InitializeComponent(); timingT.Tick += new EventHandler(timingT_Tick); timingT.Enabled = true; } void timingT_Tick(object sender, EventArgs e) { foreach (Task t in lt) { if (!t.Condition) { if (DateTime.Now == t.Time) { switch (t.Kind) { case tType.a: a(timingT, new EventArgs()); break; case tType.b: b(timingT, new EventArgs()); break; case tType.c: c(timingT, new EventArgs()); break; } } } } } void a(object sender,EventArgs e) { label1.Text += ’a’; } void b(object sender,EventArgs e) { label1.Text += ’b’; } void c(object sender,EventArgs e) { label1.Text += ’c’; } private void button1_Click(object sender, EventArgs e) { groupBox1.Visible = true; } private void tType_CheckedChanged(object sender, EventArgs e) { switch (((RadioButton)sender).Text) { case “a“: type = tType.a; break; case “b“: type = tType.b; break; case “c“: type = tType.c; break; } } private void Condition_CheckedChanged(object sender, EventArgs e) { numericUpDown1.Enabled = Condition = radioButton2.Equals(sender); maskedTextBox1.Enabled = !Condition; } private void button3_Click(object sender, EventArgs e) { if (textBox1.Text != string.Empty) { try { if (Condition) { lt.Add(new Task(textBox1.Text, type, Condition, (int)numericUpDown1.Value)); Timer t=new Timer(); t.Interval=(int)numericUpDown1.Value*1000; t.Enabled = true; switch (type) { case tType.a: t.Tick += new EventHandler(a); break; case tType.b: t.Tick += new EventHandler(b); break; case tType.c: t.Tick += new EventHandler(c); break; } cycleT.Add(t); } else { lt.Add(new Task(textBox1.Text, type, Condition, DateTime.Parse(maskedTextBox1.Text))); } listBox1.Items.Add(textBox1.Text); } catch { } finally { groupBox1.Hide(); } } } } public class Task { public string Name { get; set; } public Form1.tType Kind { get; set; } public bool Condition { get; set; } public int sec { get; set; } public DateTime Time { get; set; } //定义各种属性描述这个任务 public Task(string name, Form1.tType kind, bool condition, int seconds) { Name = name; Kind = kind; Condition = condition; sec = seconds;//初始化 } public Task(string name, Form1.tType kind, bool condition, DateTime d) { Name = name; Kind = kind; Condition = condition; Time = d;//初始化 } }}//-------------------------------------------------//-------------------------------------------------//-------------------------------------------------//Form1.Designer.csnamespace Example_Task{ partial class Form1 { /// 《summary》 /// 必需的设计器变量。 /// 《/summary》 private System.ComponentModel.IContainer components = null; /// 《summary》 /// 清理所有正在使用的资源。 /// 《/summary》 /// 《param name=“disposing“》如果应释放托管资源,为 true;否则为 false。《/param》 protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows 窗体设计器生成的代码 /// 《summary》 /// 设计器支持所需的方法 - 不要 /// 使用代码编辑器修改此方法的内容。 /// 《/summary》 private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.listBox1 = new System.Windows.Forms.ListBox(); this.button1 = new System.Windows.Forms.Button(); this.groupBox1 = new System.Windows.Forms.GroupBox(); this.button3 = new System.Windows.Forms.Button(); this.groupBox3 = new System.Windows.Forms.GroupBox(); this.radioButton3 = new System.Windows.Forms.RadioButton(); this.label3 = new System.Windows.Forms.Label(); this.numericUpDown1 = new System.Windows.Forms.NumericUpDown(); this.radioButton2 = new System.Windows.Forms.RadioButton(); this.groupBox2 = new System.Windows.Forms.GroupBox(); this.radioButton5 = new System.Windows.Forms.RadioButton(); this.radioButton4 = new System.Windows.Forms.RadioButton(); this.radioButton1 = new System.Windows.Forms.RadioButton(); this.textBox1 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.maskedTextBox1 = new System.Windows.Forms.MaskedTextBox(); this.groupBox1.SuspendLayout(); this.groupBox3.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit(); this.groupBox2.SuspendLayout(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(12, 137); this.label1.Name = “label1“; this.label1.Size = new System.Drawing.Size(590, 334); this.label1.TabIndex = 0; this.label1.Text = “任务运行情况 - “; // // listBox1 // this.listBox1.FormattingEnabled = true; this.listBox1.ItemHeight = 12; this.listBox1.Location = new System.Drawing.Point(12, 9); this.listBox1.Name = “listBox1“; this.listBox1.Size = new System.Drawing.Size(238, 124); this.listBox1.TabIndex = 1; // // button1 // this.button1.Location = new System.Drawing.Point(258, 23); this.button1.Name = “button1“; this.button1.Size = new System.Drawing.Size(75, 97); this.button1.TabIndex = 2; this.button1.Text = “New Task“; this.button1.UseVisualStyleBackColor = true; this.button1.Click += new System.EventHandler(this.button1_Click); // // groupBox1 // this.groupBox1.Controls.Add(this.button3); this.groupBox1.Controls.Add(this.groupBox3); this.groupBox1.Controls.Add(this.groupBox2); this.groupBox1.Controls.Add(this.textBox1); this.groupBox1.Controls.Add(this.label2); this.groupBox1.Location = new System.Drawing.Point(339, 9); this.groupBox1.Name = “groupBox1“; this.groupBox1.Size = new System.Drawing.Size(263, 125); this.groupBox1.TabIndex = 3; this.groupBox1.TabStop = false; this.groupBox1.Text = “TaskInfo“; this.groupBox1.Visible = false; // // button3 // this.button3.Location = new System.Drawing.Point(172, 12); this.button3.Name = “button3“; this.button3.Size = new System.Drawing.Size(75, 23); this.button3.TabIndex = 4; this.button3.Text = “OK“; this.button3.UseVisualStyleBackColor = true; this.button3.Click += new System.EventHandler(this.button3_Click); // // groupBox3 // this.groupBox3.Controls.Add(this.maskedTextBox1); this.groupBox3.Controls.Add(this.radioButton3); this.groupBox3.Controls.Add(this.label3); this.groupBox3.Controls.Add(this.numericUpDown1); this.groupBox3.Controls.Add(this.radioButton2); this.groupBox3.Location = new System.Drawing.Point(74, 41); this.groupBox3.Name = “groupBox3“; this.groupBox3.Size = new System.Drawing.Size(183, 78); this.groupBox3.TabIndex = 3; this.groupBox3.TabStop = false; this.groupBox3.Text = “Condition“; // // radioButton3 // this.radioButton3.AutoSize = true; this.radioButton3.Location = new System.Drawing.Point(6, 35); this.radioButton3.Name = “radioButton3“; this.radioButton3.Size = new System.Drawing.Size(89, 16); this.radioButton3.TabIndex = 3; this.radioButton3.TabStop = true; this.radioButton3.Text = “CertainTime“; this.radioButton3.UseVisualStyleBackColor = true; this.radioButton3.CheckedChanged += new System.EventHandler(this.Condition_CheckedChanged); // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(122, 18); this.label3.Name = “label3“; this.label3.Size = new System.Drawing.Size(47, 12); this.label3.TabIndex = 2; this.label3.Text = “Seconds“; // // numericUpDown1 // this.numericUpDown1.Enabled = false; this.numericUpDown1.Location = new System.Drawing.Point(60, 13); this.numericUpDown1.Name = “numericUpDown1“; this.numericUpDown1.Size = new System.Drawing.Size(61, 21); this.numericUpDown1.TabIndex = 1; this.numericUpDown1.Value = new decimal(new int { 1, 0, 0, 0}); // // radioButton2 // this.radioButton2.AutoSize = true; this.radioButton2.Location = new System.Drawing.Point(6, 14); this.radioButton2.Name = “radioButton2“; this.radioButton2.Size = new System.Drawing.Size(53, 16); this.radioButton2.TabIndex = 0; this.radioButton2.TabStop = true; this.radioButton2.Text = “Every“; this.radioButton2.UseVisualStyleBackColor = true; this.radioButton2.CheckedChanged += new System.EventHandler(this.Condition_CheckedChanged); // // groupBox2 // this.groupBox2.Controls.Add(this.radioButton5); this.groupBox2.Controls.Add(this.radioButton4); this.groupBox2.Controls.Add(this.radioButton1); this.groupBox2.Location = new System.Drawing.Point(6, 41); this.groupBox2.Name = “groupBox2“; this.groupBox2.Size = new System.Drawing.Size(63, 78); this.groupBox2.TabIndex = 2; this.groupBox2.TabStop = false; this.groupBox2.Text = “Type“; // // radioButton5 // this.radioButton5.AutoSize = true; this.radioButton5.Location = new System.Drawing.Point(6, 56); this.radioButton5.Name = “radioButton5“; this.radioButton5.Size = new System.Drawing.Size(29, 16); this.radioButton5.TabIndex = 2; this.radioButton5.TabStop = true; this.radioButton5.Text = “c“; this.radioButton5.UseVisualStyleBackColor = true; this.radioButton5.CheckedChanged += new System.EventHandler(this.tType_CheckedChanged); // // radioButton4 // this.radioButton4.AutoSize = true; this.radioButton4.Location = new System.Drawing.Point(6, 38); this.radioButton4.Name = “radioButton4“; this.radioButton4.Size = new System.Drawing.Size(29, 16); this.radioButton4.TabIndex = 1; this.radioButton4.TabStop = true; this.radioButton4.Text = “b“; this.radioButton4.UseVisualStyleBackColor = true; this.radioButton4.CheckedChanged += new System.EventHandler(this.tType_CheckedChanged); // // radioButton1 // this.radioButton1.AutoSize = true; this.radioButton1.Location = new System.Drawing.Point(6, 16); this.radioButton1.Name = “radioButton1“; this.radioButton1.Size = new System.Drawing.Size(29, 16); this.radioButton1.TabIndex = 0; this.radioButton1.TabStop = true; this.radioButton1.Text = “a“; this.radioButton1.UseVisualStyleBackColor = true; this.radioButton1.CheckedChanged += new System.EventHandler(this.tType_CheckedChanged); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(53, 14); this.textBox1.Name = “textBox1“; this.textBox1.Size = new System.Drawing.Size(100, 21); this.textBox1.TabIndex = 1; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(18, 17); this.label2.Name = “label2“; this.label2.Size = new System.Drawing.Size(29, 12); this.label2.TabIndex = 0; this.label2.Text = “Name“; // // maskedTextBox1 // this.maskedTextBox1.Enabled = false; this.maskedTextBox1.Location = new System.Drawing.Point(6, 51); this.maskedTextBox1.Mask = “0000-00-00 90:00:00“; this.maskedTextBox1.Name = “maskedTextBox1“; this.maskedTextBox1.Size = new System.Drawing.Size(143, 21); this.maskedTextBox1.TabIndex = 4; this.maskedTextBox1.ValidatingType = typeof(System.DateTime); // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(614, 480); this.Controls.Add(this.groupBox1); this.Controls.Add(this.button1); this.Controls.Add(this.listBox1); this.Controls.Add(this.label1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.Name = “Form1“; this.Text = “Form1“; this.groupBox1.ResumeLayout(false); this.groupBox1.PerformLayout(); this.groupBox3.ResumeLayout(false); this.groupBox3.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit(); this.groupBox2.ResumeLayout(false); this.groupBox2.PerformLayout(); this.ResumeLayout(false); } #endregion private System.Windows.Forms.Label label1; private System.Windows.Forms.ListBox listBox1; private System.Windows.Forms.Button button1; private System.Windows.Forms.GroupBox groupBox1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Button button3; private System.Windows.Forms.GroupBox groupBox3; private System.Windows.Forms.RadioButton radioButton3; private System.Windows.Forms.Label label3; private System.Windows.Forms.NumericUpDown numericUpDown1; private System.Windows.Forms.RadioButton radioButton2; private System.Windows.Forms.GroupBox groupBox2; private System.Windows.Forms.RadioButton radioButton1; private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.RadioButton radioButton4; private System.Windows.Forms.RadioButton radioButton5; private System.Windows.Forms.MaskedTextBox maskedTextBox1; }}/*没有太多的容错方法,为了简洁,尽量直达目的。这个窗体可以定时或周期性执行任务仔细看看Form1.cs有点多线程的思路,但这里没有用多线程。只要改写a(),b(),c() 就能完成你的任务,用同样的方法添加函数对应不同任务种类。这下改明白了吧多加点分吧*/

mysql中的时间类型timestamp 允许为空值,但是不可以自定义值,所以为空值时没有任何意义对么

  可以把时间的格式转换成时间戳的格式保存,他们的区别:  datetime  1、允许为空值,可以自定义值,系统不会自动修改其值。  2、不可以设定默认值,所以在不允许为空值的情况下,必须手动指定datetime字段的值才可以成功插入数据。  3、虽然不可以设定默认值,但是可以在指定datetime字段的值的时候使用now()变量来自动插入系统的当前时间。  timestamp  1、允许为空值,但是不可以自定义值,所以为空值时没有任何意义。  2、默认值为CURRENT_TIMESTAMP(),其实也就是当前的系统时间。  3、数据库会自动修改其值,所以在插入记录时不需要指定timestamp字段的名称和timestamp字段的值,你只需要在设计表的时候添加一个timestamp字段即可,插入后该字段的值会自动变为当前系统时间。  4、以后任何时间修改表中的记录时,对应记录的timestamp值会自动被更新为当前的系统时间。