Skip to content

Instantly share code, notes, and snippets.

@androidcodehunter
Created November 6, 2016 07:13
Show Gist options
  • Save androidcodehunter/eacd29f7a9841f3a5540b173087fc9a2 to your computer and use it in GitHub Desktop.
Save androidcodehunter/eacd29f7a9841f3a5540b173087fc9a2 to your computer and use it in GitHub Desktop.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(getString(R.string.new_group));
final FrameLayout input = (FrameLayout) View.inflate(this, R.layout.dialog_profile_name_update, null);
final EditText editText = (EditText) input.findViewById(R.id.et_rename_profile_name);
editText.setHint(getString(R.string.hint_name_this_group_chat));
editText.setText(getString(R.string.label_group));
editText.setSelection(getString(R.string.label_group).length());
builder.setView(input);
builder.setPositiveButton(getString(R.string.dialog_positive_btn_ok), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String groupName = editText.getText().toString().trim();
ArrayList<MemberModel> memberList = getGroupMemberList();
if (!TextUtils.isEmpty(groupName)) {
if (groupName.matches(Utils.GROUP_NAME_REGEX)) {
createGroup(groupName, memberList);
} else {
editText.setError(getString(R.string.text_invalid_group_name));
}
} else {
Toast.makeText(context, getString(R.string.toast_group_name_empty), Toast.LENGTH_SHORT).show();
}
}
});
builder.setNegativeButton(getString(R.string.dialog_negative_btn_cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {}});
AlertDialog alert = builder.create();
alert.show();
Button negativeButton = alert.getButton(DialogInterface.BUTTON_NEGATIVE);
negativeButton.setTextColor(ContextCompat.getColor(this, R.color.dialog_new_group_positive_button));
Button positiveButton = alert.getButton(DialogInterface.BUTTON_POSITIVE);
positiveButton.setTextColor(ContextCompat.getColor(this, R.color.dialog_new_group_positive_button));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment