I have activity
with two fragments
. I do not use <fragment/>
tags, I have two classes that extend Fragment
, in this fragment I have:
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.bfragment, container, false); // this will inflate the Fragment in activity. }
Now the problem is that I get several broadcast receivers in activity, from which some receivers update the user interface from the first fragment, and some update the user interface from the second.
One of my broadcast receivers, defined in my main characteristic:
private BroadcastReceiver bcReceived = new BroadcastReceiver() { @Override public void onReceive(Context arg0, Intent intent) { Log.d("", "BC Object Received"); ActionBar actionbar = getActionBar(); actionbar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); ActionBar.Tab bTab = actionbar.newTab().setText("B"); Fragment fragment = new BFragment(); bTab.setTabListener(new MyTabsListener(fragment)); actionbar.addTab(bTab, true); final LinearLayout linearLayout = (LinearLayout) findViewById(R.id.bTable);
I want to use the above linearLayout and use it to inflate the view. But getting NPE.
here, when some broadcast receivers update the first fragment, it works correctly, but when the broadcast receiver updates the second fragment from activity, I get NPE.
My question is: How and where should the fragment be updated? Should it be inside my work? if so, in which method? if not, where should I update the fragment?
Please help me!!!