以下是我的代码。现在我想保存以前的当前点击并希望将之前的视图传递回后退按钮
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;
}
}
答案 0 :(得分:0)
我以不同的方式做到这一点,但也许我的代码可以帮助你。
我有ListFragment
,当我点击列表项时,我会使用新的Fragment
更改它,当我按下后退按钮时,我会返回ListFragment
。
Here it is。我在Fragments
中有ViewPager
,但您可以省略它。