安卓應用開發常用代碼

來源:互聯網
上載者:User

標籤: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) });


 

 

 

安卓應用開發常用代碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.