-1

following is my code.Now I want to save previous current click and want to pass previous view to back button

public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.footer_item_list,
        container, false);


    field_button =(ImageButton) view.findViewById(R.id.field_icon);
    field_button.setImageResource(R.drawable.field_ico_selected);
    field_button.setOnClickListener(this);

    cluster_button =(ImageButton) view.findViewById(R.id.cluster_icon);
    cluster_button.setImageResource(R.drawable.cluster_ico);
    cluster_button.setOnClickListener(this);

    platform_button =(ImageButton) view.findViewById(R.id.platform_icon);
    platform_button.setImageResource(R.drawable.platform_ico);
    platform_button.setOnClickListener(this);

    well_butn =(ImageButton) view.findViewById(R.id.well_icon);
    well_butn.setImageResource(R.drawable.well_ico);
    well_butn.setOnClickListener(this);

    alarm_butn =(ImageButton) view.findViewById(R.id.alarm_icon);
    alarm_butn.setOnClickListener(this);

    help_butn =(ImageButton) view.findViewById(R.id.info_icon);
    help_butn.setOnClickListener(this);
    return view;
  }


  private void doFragmentTransaction(int sourceLayoutID, Fragment destinationFragment ) {
    FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();                 
    fragmentTransaction.replace(sourceLayoutID, destinationFragment);
    fragmentTransaction.commit();

  }

@Override
public void onClick(View v) {

    if(v == field_button) {     

          FieldActivity fieldCarouselFragment = new FieldActivity();
          SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_FIELD_OVERVIEW;
          doFragmentTransaction(R.id.carouselLayout,fieldCarouselFragment ); 


        }

    else if(v == cluster_button) {

              ClusterActivity clusterCarouselFragment = new ClusterActivity();
              SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_CLUSTER_SAMARANG_A;
              doFragmentTransaction(R.id.carouselLayout,clusterCarouselFragment ); 

            }

    else if(v == platform_button) {

                 PlatformActivity platformCarouselFragment = new  PlatformActivity();
                  SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_PLATFORM;
                  doFragmentTransaction(R.id.carouselLayout,platformCarouselFragment); 


            }

    else if(v == well_butn) {

                    WellPerfrmActivity wellCarouselFragment = new WellPerfrmActivity();
                    SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_STRING_SM09L;
                    doFragmentTransaction(R.id.carouselLayout,wellCarouselFragment); 


            }

    else if(v == alarm_butn) {
                Intent intent = new Intent(getActivity(), AlarmsActivity.class);
                startActivity(intent);
                SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_ALARM;

            }
        else if(v == help_butn) {
                Intent intent = new Intent(getActivity(), HelpActivity.class);
                this.startActivity(intent);
                SamAppConstants.CURRENT_SCREEN_ID_MAIN = SamAppConstants.GROUP_SCREEN_ID_HELP;
                        }

    }
Bhoomika Brahmbhatt
  • 7,404
  • 3
  • 29
  • 44
pinky
  • 13
  • 1
  • 4
  • I can't understand what you want... Would you like to replace one `Fragment` with another and go back when Back `Button` is pressed? – Lyd Sep 05 '13 at 09:57
  • yes..i hav 6 buttons in present fragment activity..each button click displays other fragment activities ..i want to pass previous fragment on back button press...eg..1st I pressed button4 den button2 now when I click back button2 view should appear – pinky Sep 05 '13 at 10:04
  • Iam replacing carousellayout on each button click.. – pinky Sep 05 '13 at 10:09

1 Answers1

0

I do it in a different way but maybe my code could help you.

I have a ListFragment and when I click on a list item, I change it with a new Fragment, and when I press back button, I return to ListFragment.

Here it is. I have that Fragments in a ViewPager, but you can omit it.

Community
  • 1
  • 1
Lyd
  • 2,106
  • 3
  • 26
  • 33
  • Iam creating fragment in linearlayout on each button click..plz can any one assist me to get previous button click – pinky Sep 05 '13 at 10:41
  • But you will always return to same view, initial fragment, isn't it? Or in your button1 view, for example, you have buttons too? – Lyd Sep 05 '13 at 10:42
  • can you please suggest me how can i get previous view of linearlayout – pinky Sep 05 '13 at 11:10