码迷,mamicode.com
首页 > 移动开发 > 详细

安卓应用开发常用代码

时间:2014-10-17 00:21:43      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   java   for   sp   

1,获取当天日期

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String updatedate = sdf.format(new java.util.Date());

2,String转Int

Integer.valueOf(str).intValue()

3,Int转String

String.valueOf(selectedtaskid)

4,Toast显示

Toast.makeText(ListComplicateTaskActivity.this, "你已经有100条记录,请先删除一些", Toast.LENGTH_LONG).show();

5,不带参数跳转activity

startActivity(new Intent(ListComplicateTaskActivity.this,ListComplicateTaskActivity.class));

6,带参数跳转activity

A:
Intent it = new Intent();
it.putExtra("selectpos", 65535);
it.setClass(ListComplicateTaskActivity.this,AddTaskActivity.class);
startActivity(it);
B:
Intent intent = this.getIntent();// 得到用于激活它的意图
position = intent.getIntExtra("selectpos", 0);

7,SQLite数据库操作

//查询
Cursor c = db.rawQuery("select * from task where taskid = ?",
                    new String[] { position + "" });

//插入
sql = "insert into task(taskid,content,priority,istop,isdeadline,deadline, updatedate) values ("
       + taskno
       + ", ‘"
       + stredit
       + "‘, "
       + radioidx
       + ", ‘"
       + isontop
       + "‘, ‘"
       + isdealine
       + "‘, ‘"
       + time + "‘, ‘" + updatedate + "‘)";
     db.execSQL(sql);

//更新

sql = "update task set istop = ‘true‘ where taskid = "
            + selectedtaskid + "";
          db.execSQL(sql);// 执行修改

//删除

db.delete( "task","taskid = ?",  new String[] { String.valueOf(selectedtaskid) });



 

安卓应用开发常用代码

标签:style   blog   color   io   os   ar   java   for   sp   

原文地址:http://www.cnblogs.com/agileyanly/p/4029956.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!