private boolean checkChannelIdExist(int newChannelId, int keyId) {
   int length = mChannelArray.size();
   for (int i = 0; i < length; i++) {
     CellBroadcastChannel tChannel = mChannelArray.get(i);
     int tempChannelId = tChannel.getChannelId();
     int tempKeyId = tChannel.getKeyId();
     if (tempChannelId == newChannelId && tempKeyId != keyId) {
       return true;
     }
   }
   return false;
 }
 private boolean updateChannelToDatabase(
     CellBroadcastChannel oldChannel, CellBroadcastChannel newChannel) {
   MmsLog.d(LOG_TAG, "updateChannelToDatabase start oldChannel =" + oldChannel);
   String[] projection = new String[] {KEYID, NAME, NUMBER, ENABLE};
   final int id = newChannel.getKeyId();
   final String name = newChannel.getChannelName();
   final boolean enable = newChannel.getChannelState();
   final int number = newChannel.getChannelId();
   ContentValues values = new ContentValues();
   values.put(KEYID, id);
   values.put(NAME, name);
   values.put(NUMBER, number);
   values.put(ENABLE, Integer.valueOf(enable ? 1 : 0));
   String where = KEYID + "=" + oldChannel.getKeyId();
   try {
     int lines = this.getContentResolver().update(mUri, values, where, null);
   } catch (IllegalArgumentException e) {
     return false;
   }
   MmsLog.d(LOG_TAG, "updateChannelToDatabase end newChannel =" + newChannel);
   return true;
 }
  private void showEditChannelDialog(final CellBroadcastChannel oldChannel) {
    int keyId = oldChannel.getKeyId();
    int cid = oldChannel.getChannelId();
    String cname = oldChannel.getChannelName();
    boolean checked = oldChannel.getChannelState();
    LayoutInflater inflater = LayoutInflater.from(this);
    final View setView = inflater.inflate(R.layout.pref_add_channel, null);
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setView(setView);
    builder.setTitle(R.string.cb_channel_dialog_edit_channel);
    final EditText channelName = (EditText) setView.findViewById(R.id.edit_channel_name);
    final EditText channelNum = (EditText) setView.findViewById(R.id.edit_channel_number);
    final CheckBox channelState = (CheckBox) setView.findViewById(R.id.checkbox_channel_enable);
    channelName.setText(cname);
    channelNum.setText(String.valueOf(cid));
    channelState.setChecked(checked);
    final AlertDialog dialog;
    builder.setPositiveButton(
        android.R.string.ok,
        new DialogInterface.OnClickListener() {
          public void onClick(DialogInterface dialog, int whichButton) {
            String name = channelName.getText().toString();
            String num = channelNum.getText().toString();
            boolean checked = channelState.isChecked();
            String errorInfo = "";
            if (!checkChannelName(name)) {
              errorInfo += getString(R.string.cb_error_channel_name);
            }
            if (!checkChannelNumber(num)) {
              errorInfo += "\n" + getString(R.string.cb_error_channel_num);
            }
            if (errorInfo.equals("")) {
              int newChannelId = Integer.valueOf(num).intValue();
              int tempOldChannelId = oldChannel.getChannelId();
              if (!checkChannelIdExist(newChannelId, oldChannel.getKeyId())) {
                dialog.dismiss();
                CellBroadcastChannel newChannel =
                    new CellBroadcastChannel(oldChannel.getKeyId(), newChannelId, name, checked);
                oldChannel.setChannelState(false);
                int tempNewChannelId = newChannel.getChannelId();
                SmsBroadcastConfigInfo[] objectList = new SmsBroadcastConfigInfo[2];
                objectList[0] =
                    new SmsBroadcastConfigInfo(tempOldChannelId, tempOldChannelId, -1, -1, false);
                objectList[1] =
                    new SmsBroadcastConfigInfo(
                        tempNewChannelId, tempNewChannelId, -1, -1, newChannel.getChannelState());
                if (updateChannelToDatabase(oldChannel, newChannel)) {
                  setCellBroadcastConfig(objectList);
                } else {
                  showUpdateDBErrorInfoDialog();
                }
              } else {
                displayMessage(getString(R.string.cb_error_channel_id_exist));
              }
            } else {
              displayMessage(errorInfo);
            }
          }
        });

    builder.setNegativeButton(android.R.string.cancel, null);
    dialog = builder.create();
    dialog.show();
    requestInputMethod(dialog);
  }