android: How to change views inside fragment on Click of a button
<p>i have an action bar tab, it has two tabs, the first tabs has a fragment with a layout containing a button, wat i want to do is is when i click the button it will kinda switch the layout of the current fragment where that button belongs.. and is there any way to this stuff?.. i have an idea but it produces an nullexception on the other tab, anyway lets just concentrate on the 1st tab wherein i want to switch views when a button is clicked, here is my sample code: </p>

<p>MainActivity:</p>

<pre><code>ActionBar acBar = getActionBar();
acBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
ActionBar.Tab tab1 = acBar.newTab().setText("Patient");
ActionBar.Tab tab2 = acBar.newTab().setText("Contact");

Fragment frag_a = new PatientFragment();
Fragment frag_b = new ContactFragment();

tab1.setTabListener(new MyTabListener(this, frag_a));
tab2.setTabListener(new MyTabListener(this, frag_b));

acBar.addTab(tab1);
acBar.addTab(tab2);
</code></pre>

<p>TabListener: </p>

<pre><code>class MyTabListener implements ActionBar.TabListener{
    private Fragment gFrag;
    private Activity gAct;

        public MyTabListener(Activity act, Fragment frag){
            this.gFrag = frag;
            this.gAct = act;
        }


        public void onTabReselected(Tab tab, FragmentTransaction ft) {
            Toast.makeText(gAct, "Reselected!", Toast.LENGTH_LONG).show();
        }

        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            ft.replace(R.id.fragment_container, gFrag);
        }

        public void onTabUnselected(Tab tab, FragmentTransaction ft) {
            ft.remove(gFrag);

        }

}
</code></pre>

<p>Fragment A:</p>

<pre><code>public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.frag_a, container, false);
    ;
    Button next = (Button) view.findViewById(R.id.prompt);

    next.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            Toast.makeText(getActivity(), "Next!",Toast.LENGTH_LONG).show();

        }
    });

    return view;
}
</code></pre>

<p>Mainly i just want to switch views in the fragment, and if there is any other way that u guys know please do share tnx!</p>
