日期:2014-05-18 浏览次数:20612 次
package com.jasson.passwordbox;
import java.text.SimpleDateFormat;
import java.util.Date;
import com.jasson.passwordbox.R;
import com.jasson.note.InternetNotes;
import com.jasson.note.Notes;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.Toast;
public class InternetWriteActivity extends Activity{
private static final SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd hh:mm:ss");
private SQLiteDatabase db;
String internetNoteId;
EditText edit;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.internet_edit);
db = openOrCreateDatabase(InternetNotes.INTERNETDBNAME,Context.MODE_PRIVATE,null);
edit=(EditText) findViewById(R.id.edit_internet);
if(getIntent().getExtras()!=null){
String internetcontent=getIntent().getExtras().getString("internetcontent").toString();
internetNoteId=getIntent().getExtras().getString("internetNoteId").toString();
if(internetcontent!=null){
edit.setText(internetcontent);
}
}
}
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater flater=getMenuInflater();
flater.inflate(R.menu.menu2, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
String content=edit.getText().toString();
int itemId=item.getItemId();
switch(itemId){
//保存
case R.id.save:
if(!content.equals("")){
db.execSQL("insert into "+InternetNotes.INTERNETDBNAME+"("+InternetNotes.INTERNETTITLE+","+InternetNotes.INTERNETCONTENT+","+InternetNotes.INTERNETLTIME+") values(?,?,?)",
new Object[]{sdf.format(new Date()),content,sdf.format(new Date())});
Toast.makeText(InternetWriteActivity.this,"信息保存成功",Toast.LENGTH_LONG).show();
InternetWriteActivity.this.finish();
}else{
Toast.makeText(InternetWriteActivity.this,"请输入信息",Toast.LENGTH_LONG).show();
}
break;
case R.id.update:
//根据id修改信息
if(internetNoteId!=null){
String content2=edit.getText().toString();
ContentValues values=new ContentValues();
values.put("content2",content2);
db.update(Inter