我收到后,我正在adapter.notifyDataSetChanged()
和listView.invalidateViews()
如果条件说“blabla”成立,则接听电话。但我的UI仍然没有得到更新。
public class UserFragment extends Fragment{
public class FragmentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(getSetting("CurrentView","").equalsIgnoreCase("blabla")){
adapter.notifyDataSetChanged();
listView.invalidateViews(); //this is not updating the UI.
}
}
注意:我尝试通过再次替换相同的片段来调用相同的UserFragment.java
来更新更改,但这虽然更新了UI但却提供了例外 - IllegalStateException: Can not perform this action after onSaveInstanceState
我在onReceive
方法中的其余代码 -
UserFragment firstFragment = new UserFragment ();
getSupportFragmentManager().beginTransaction()
.replace(R.id.headlines_fragment, firstFragment)
.addToBackStack(null).commit(); //IllegalStateException: Can not perform this action after onSaveInstanceState
有什么想法吗?
答案 0 :(得分:0)
试试这个
public class UserFragment extends Fragment{
public class FragmentReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(getSetting("CurrentView","").equalsIgnoreCase("blabla")){
adapter.notifyDataSetChanged();
listView.invalidateViews(); //this is not updating the UI.
UserFragment.this.onCreate(savedInstanceState);
}
}