安卓应用开发常用代码

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



 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。