1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| @Override public void onClick(View v) { switch (v.getId()) { case R.id.tv_nickname: inputDialog("nickname", "修改用户昵称", User.nickname); break; } }
private String inputDialog(final String aim, String title, String def) { final String[] result = new String[1]; LayoutInflater factory = LayoutInflater.from(PersonActivity.this); final View view = factory.inflate(R.layout.edit_box, null); final EditText edit = (EditText) view.findViewById(R.id.editText); edit.setText(def); new AlertDialog.Builder(PersonActivity.this) .setTitle(title) .setView(view) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { result[0] = edit.getText().toString(); onInputDialog(aim, edit.getText().toString()); } }) .setNegativeButton("取消", null) .create().show(); return result[0]; }
private void onInputDialog(String aim, String s) {
switch (aim) { case "nickname": if (!canMatch(s, "\\S+")) { App.toast("用户名不能有空格"); return; } mNicknameTv.setText(User.nickname = s); break; }
updateContent(aim, s); }
private void updateContent(final String key, final String val) { String path = Paths.getNetpath("updateUserInfo"); String[] params = new String[]{"user_id", User.id(), key, val}; ConnectUtil.Get(path, params, new StringCallback(){ @Override public void onFinish(String result) { if (result.equals("OK")) { Snackbar.make(findViewById(R.id.fab), "修改成功", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } else if (!result.isEmpty()) { Snackbar.make(findViewById(R.id.fab), "修改失败:"+ StringUtil.getXml(result, "result"), Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } } }); }
boolean canMatch(String str, String pat) { return StringUtil.canMatch(str, pat); }
|