1

I have an fragment layout in android. The left pane has an listfragment that has list of options and right side pane has details or forms specific to the item selected from left side's listfragment pane. Now Till this i have done and its working But what i want is that the form in the right side pane should have some buttons and other controls and clicking on a button "view Info" a different layout should come in the same place i.e details pane area. Now one thing is that the details area that has a layout with "view info" button is an inflated layout in DetailsFragment. public View onCreateView() method.

 @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
       if (container == null) {            
        return null;
    }      


       View v = inflater.inflate(R.layout.listviewitems, null);


       ListView lv = (ListView) v.findViewById(R.id.listv);
       TextView tv=(TextView)v.findViewById(R.id.tvtitle);
       Button verify=(Button)v.findViewById(R.id.button1);

       verify.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

 // I want to write a code for display next screen here.
        }

    });

       Bundle b = getArguments();
       String itemclick = null;
       if(b.getInt("index")==0)
       {
           itemclick="pending order";
       }
       else if(b.getInt("index")==1)
       {
           itemclick="orders recieved today";
       }
       else if(b.getInt("index")==2)
       {
           itemclick="todays orders";
       }
       tv.setText(itemclick);

       populateItemlist();
       lv.invalidateViews();         


       return v;          
}

You can see the screen shot http://www.freeimagehosting.net/fi878. The button click will also need to be performing some db tasks before displaying next UI that i have not mentioned here. But my main question is how to display a different layout in the same place on button's click. Plz help me as am new to android.

1 Answers1

0

Use FragmentTransaction, and replace the older Fragment with new Fragment.

FragmentTransaction ft = getFragmentManager().beginTransaction();

DetailsFragment newFragment = DetailsFragment.newInstance();
ft.replace(R.id.details_fragment_container, newFragment, "detailFragment");
ft.commit();
jeet
  • 29,001
  • 6
  • 52
  • 53
  • And for that is it compulsary to declare a fragment for every layout in my mainactivity.xml??? because the code i have put here is of a class public class DetailsFragment extends Fragment – user1661935 Sep 11 '12 at 06:19