0

我正在做adapter.notifyDataSetChanged()listView.invalidateViews()如果条件说“blabla”为真,我接到接听电话后。但是我的用户界面仍然没有更新。

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

有任何想法吗?

4

1 回答 1

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);

}
}
于 2013-04-02T11:46:06.657 回答