-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

私は別の方法でそれを行いますが、私のコードが役立つかもしれません。

ListFragmentリスト項目をクリックすると があり、新しい に変更し、戻るFragmentボタンを押すと に戻りますListFragment

ここにあります。にそれFragmentsがありViewPagerますが、省略できます。

于 2013-09-05T10:14:17.503 に答える