首页 > 代码库 > 安卓应用开发常用代码

安卓应用开发常用代码

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) });

 

安卓应用开发常用代码