public User[] getAllUser() {
   Vector<User> v = new Vector<User>();
   Cursor cursor = null;
   try {
     cursor = db.find("select * from " + TABLENAME, null);
     while (cursor.moveToNext()) {
       User temp = new User();
       temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB")));
       temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS)));
       temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ)));
       temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI)));
       temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME)));
       temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE)));
       v.add(temp);
     }
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) cursor.close();
     db.closeConnection();
   }
   if (v.size() > 0) {
     return v.toArray(new User[] {});
   } else {
     User[] users = new User[1];
     User user = new User();
     user.setName("无结果111");
     users[0] = user;
     return users;
   }
 }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    switch (id) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          User user = new User();
          user.setName(nameET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(this);
          if (ct.addData(user)) {
            Toast.makeText(this, "添加成功!", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(this, "添加失败!", Toast.LENGTH_LONG).show();
          }
        } else {
          Toast.makeText(this, "请先输入姓名!", Toast.LENGTH_LONG).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {

    switch (item.getItemId()) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          user.setName(nameET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(UpdateContactsActivity.this);

          // 修改数据库联系人信息
          if (ct.updateUser(user)) {
            Toast.makeText(UpdateContactsActivity.this, "修改成功!", Toast.LENGTH_SHORT).show();
          } else {
            Toast.makeText(UpdateContactsActivity.this, "修改失败!", Toast.LENGTH_SHORT).show();
          }
        } else {
          Toast.makeText(UpdateContactsActivity.this, "数据不能为空!", Toast.LENGTH_SHORT).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }
    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    switch (id) {
      case 1:
        if (!nameET.getText().toString().equals("")) {
          User user = new User();
          user.setName(nameET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(this);
          if (ct.addData(user)) {
            Toast.makeText(this, "添加成功", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(this, "添加失败", Toast.LENGTH_LONG).show();
          }

        } else {
          Toast.makeText(this, "请先输入姓名", Toast.LENGTH_LONG).show();
        }
        break;
      case 2:
        finish();
        break;
      default:
        break;
    }

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
      return true;
    }

    return super.onOptionsItemSelected(item);
  }
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    switch (id) {
      case 1: // 保存
        if (!nameET.getText().toString().equals("")) {
          user.setName(nameET.getText().toString());
          user.setDanwei(danweiET.getText().toString());
          user.setMobile(mobileET.getText().toString());
          user.setQq(qqET.getText().toString());
          user.setAddress(addressET.getText().toString());
          ContactsTable ct = new ContactsTable(UpdateContactsActivity.this);

          // 修改数据库联系人信息
          if (ct.updateUser(user)) {
            Toast.makeText(UpdateContactsActivity.this, "修改成功!", Toast.LENGTH_LONG).show();
          } else {
            Toast.makeText(UpdateContactsActivity.this, "修改失败!", Toast.LENGTH_LONG).show();
          }
        } else {
          Toast.makeText(UpdateContactsActivity.this, "数据不能为空!", Toast.LENGTH_LONG).show();
        }
        break;
      case 2: // 返回
        finish();
        break;
      default:
        break;
    }
    /*//noinspection SimplifiableIfStatement
            if (id == R.id.action_settings) {
                return true;
            }
    */
    return super.onOptionsItemSelected(item);
  }
 public User getUserByID(int id) {
   Cursor cursor = null;
   try {
     cursor = db.find("select * from " + TABLENAME + " where id_DB=?", new String[] {id + ""});
     User temp = new User();
     cursor.moveToNext();
     temp.setId_DB(cursor.getInt(cursor.getColumnIndex("id_DB")));
     temp.setAddress(cursor.getString(cursor.getColumnIndex(User.ADDRESS)));
     temp.setQq(cursor.getString(cursor.getColumnIndex(User.QQ)));
     temp.setDanwei(cursor.getString(cursor.getColumnIndex(User.DANWEI)));
     temp.setMobile(cursor.getString(cursor.getColumnIndex(User.MOBILE)));
     temp.setName(cursor.getString(cursor.getColumnIndex(User.NAME)));
     return temp;
   } catch (Exception e) {
     e.printStackTrace();
   } finally {
     if (cursor != null) {
       cursor.close();
     }
     db.closeConnection();
   }
   return null;
 }