3).在数据库版本变化时请删除diary表,并重新创建出diary表。

  publicclass DBHelper extends SQLiteOpenHelper{

  public final static String DATABASENAME ="diaryOpenHelper.db";

  public final static int DATABASEVERSION =1;

  //创建数据库

  public DBHelper(Context context,Stringname,CursorFactory factory,int version)

  {

  super(context, name, factory,version);

   }

  //创建表等机构性文件

  public void onCreate(SQLiteDatabase db)

  {

  String sql ="create tablediary"+

  "("+

  "_idinteger primary key autoincrement,"+

  "topicvarchar(100),"+

  "contentvarchar(1000)"+

  ")";

  db.execSQL(sql);

  }

  //若数据库版本有更新,则调用此方法

  public void onUpgrade(SQLiteDatabasedb,int oldVersion,int newVersion)

  {

  String sql = "drop table ifexists diary";

  db.execSQL(sql);

  this.onCreate(db);

  }

  }

  37. 页面上现有ProgressBar控件progressBar,请用书写线程以10秒的的时间完成其进度显示工作。(10分)答案

  publicclass ProgressBarStu extends Activity {

  private ProgressBar progressBar = null;

  protected void onCreate(BundlesavedInstanceState) {

  super.onCreate(savedInstanceState);

  setContentView(R.layout.progressbar);

  //从这到下是关键

  progressBar = (ProgressBar)findViewById(R.id.progressBar);

  Thread thread = new Thread(newRunnable() {

  @Override

  public void run() {

  int progressBarMax =progressBar.getMax();

  try {

  while(progressBarMax!=progressBar.getProgress())

  {

  intstepProgress = progressBarMax/10;

  intcurrentprogress = progressBar.getProgress();

  progressBar.setProgress(currentprogress+stepProgress);

  Thread.sleep(1000);

  }

  } catch(InterruptedException e) {

  // TODO Auto-generatedcatch block

  e.printStackTrace();

  }

  }

  });

  thread.start();

  //关键结束

  }

  }