gpt4 book ai didi

android - 我希望在关闭对话框 fragment 后刷新/重绘 Activity 。我该如何实现?

转载 作者:行者123 更新时间:2023-12-04 17:58:57 25 4
gpt4 key购买 nike

初看起来是这样的:

The image description of the first image

这是按下“编辑”时弹出的对话框 fragment ,我希望在关闭对话框 fragment 后在 Activity 中看到更改。 The image description of the second image

public Dialog onCreateDialog(Bundle savedInstanceState) {
final View view = getActivity().getLayoutInflater().inflate(R.layout.edit_profile_dialog, new LinearLayout(getActivity()), false);
editProfile = (EditText) view.findViewById(R.id.changeProfile);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
setupProgressDialog();
/*get value from Bundle*/
String editValue = getArguments().getString("value", "");
editProfile.setText(editValue);
String title = getArguments().getString("title", "");
builder.setTitle(title);
builder.setView(view);
builder.setCancelable(false);
builder.setPositiveButton("Ok!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
/*edit the value in shared preference*/
sharedPref = getActivity().getSharedPreferences(getString(R.string.sharedPref), 0);
editor = sharedPref.edit();
editor.putString(getArguments().getString("saved", ""), editProfile.getText().toString());
editor.apply();
ID= sharedPref.getString("id", null);
access_token=sharedPref.getString("token",null);
//Start of AsyncTask after this

最佳答案

如果您只需要更新用户从对话框中输入的数据,则不必重绘整个布局。

您只能将用户名设置为相关的 TextView 并关闭对话框 fragment 。

TextView yourNameTextView = (TextView)findViewById(R.id.your_textview);

public void setNameToTextView(String name){
yourNameTextView.setText(name);
}

当用户点击 Ok 按钮时,您可以调用:

((YourActivity)getActivity).setText(input);

祝你好运。

关于android - 我希望在关闭对话框 fragment 后刷新/重绘 Activity 。我该如何实现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37803024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com