-1

以下是我的代码。现在我想保存上一次当前单击并想将上一个视图传递给后退按钮

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;
                        }

    }
4

1 回答 1

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.

于 2013-09-05T10:14:17.503 回答