我在做adapter.notifyDataSetChanged()
和listView.invalidateViews()
我得到 接到电话后,如果条件说“blabla”变为true。但是我的用户界面还没有更新。收到广播接收方意向后没有反映变化
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
再次更换相同的片段来更新改变,但是这虽然更新的用户界面,但在onReceive
给予者除外IllegalStateException: Can not perform this action after onSaveInstanceState
我的代码的其余部分方法 -
UserFragment firstFragment = new UserFragment();
getSupportFragmentManager().beginTransaction()
.replace(R.id.headlines_fragment, firstFragment)
.addToBackStack(null).commit(); //IllegalStateException: Can not perform this action after onSaveInstanceState
任何想法?
使这被显示在适配器确保数据改变你叫notifydatasetchanged的适配器之前。 –
是的,只有当我转到其他视图然后再次返回到此视图,但不是立即在同一视图内时,它才会发生变化。 –
尝试再次调用onCreate(bundle),这是一个肮脏的技巧,但工程。 –