Android:refresh/update 来自另一个 activity 单击按钮的片段
Android: refresh/update fragment from another activity on button clicked
我在 mainActivity
中有一个对话框提示。如果用户关闭对话框,我需要向 fourthFragment
中的 ListView 项目之一显示红点(如下图中 fourthFragment
中的红框所示)。
问题是红点只有在我关闭应用程序并重新打开后才会更新,因为 fourthFragment
在用户关闭对话框之前已经完成创建。如何在Dialog关闭后refresh/updatefourthFragment
立即显示红点?
简短描述:
mainActivity
: 在对话框关闭时 > 将 showRedDot
="1" 存储到本地数据库
fourthFragment
: onCreate > 从本地数据库读取 showRedDot
,如果为“1”,则显示红点。 (这里的问题,当 onCreate 时,showRedDot
仍然是“0”,所以我需要在对话框关闭后更新 fourthFragment
布局。)
您调用了一个接口来推送对话框的事件关闭(按钮单击)。
像这样:
public interface MyDialogListener {
void OnCloseDialog();
}
public class fourthFragment extend Fragment implements MyDialogListener {
public void SomeMethod() {
MyDialog myDialog = new MyDialog(this, this);
myDialog.show();
}
public void OnCloseDialog() {
// Do update your listview in here( maybe call method initialize data for listview)
}
}
public class MyDialog extends Dialog {
MyDialogListener mListener;
public MyDialog (Context context, MyDialogListener listener) {
super(context, R.style.Dialog);
mListener = listener;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.CloseButton:
// Push event when Dialog close(or anything)
mListener.OnCloseDialog();
dismiss()
break;
default:
//...
}
}
}
按照上面的方法尝试接口或广播接收器。如果否则将片段刷新为
// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();
我在 mainActivity
中有一个对话框提示。如果用户关闭对话框,我需要向 fourthFragment
中的 ListView 项目之一显示红点(如下图中 fourthFragment
中的红框所示)。
问题是红点只有在我关闭应用程序并重新打开后才会更新,因为 fourthFragment
在用户关闭对话框之前已经完成创建。如何在Dialog关闭后refresh/updatefourthFragment
立即显示红点?
简短描述:
mainActivity
: 在对话框关闭时 > 将showRedDot
="1" 存储到本地数据库fourthFragment
: onCreate > 从本地数据库读取showRedDot
,如果为“1”,则显示红点。 (这里的问题,当 onCreate 时,showRedDot
仍然是“0”,所以我需要在对话框关闭后更新fourthFragment
布局。)
您调用了一个接口来推送对话框的事件关闭(按钮单击)。 像这样:
public interface MyDialogListener {
void OnCloseDialog();
}
public class fourthFragment extend Fragment implements MyDialogListener {
public void SomeMethod() {
MyDialog myDialog = new MyDialog(this, this);
myDialog.show();
}
public void OnCloseDialog() {
// Do update your listview in here( maybe call method initialize data for listview)
}
}
public class MyDialog extends Dialog {
MyDialogListener mListener;
public MyDialog (Context context, MyDialogListener listener) {
super(context, R.style.Dialog);
mListener = listener;
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.CloseButton:
// Push event when Dialog close(or anything)
mListener.OnCloseDialog();
dismiss()
break;
default:
//...
}
}
}
按照上面的方法尝试接口或广播接收器。如果否则将片段刷新为
// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();