在这些Android文档的帮助下,我试图做一个操作栏的后退按钮。我得到一个如下所示的操作栏的后退按钮:
输出:
但是我的问题是,观看图库图像后,按action bar back button
。
然后it is not working
。但是必须go back to previous page
。
下面列出的是编码。
GalleryActivity.java:
import android.app.ActionBar;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;
import com.fth.android.R;
public class GalleryActivity extends FragmentActivity {
private int position;
private static String id;
private static String name;
private DemoCollectionPagerAdapter mDemoCollectionPagerAdapter;
private ViewPager mViewPager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_gallery);
position = getIntent().getExtras().getInt("position");
id = getIntent().getExtras().getString("id");
name = getIntent().getExtras().getString("name");
mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager());
// Set up action bar.
final ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
// getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME|ActionBar.DISPLAY_USE_LOGO|ActionBar.DISPLAY_HOME_AS_UP);
// Set up the ViewPager, attaching the adapter.
mViewPager = (ViewPager) findViewById(R.id.pager);
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
Intent upIntent = new Intent(this, HomeActivity.class);
upIntent.putExtra("position", position);
if (NavUtils.shouldUpRecreateTask(this, upIntent)) {
TaskStackBuilder.from(this)
.addNextIntent(upIntent)
.startActivities();
finish();
} else {
NavUtils.navigateUpTo(this, upIntent);
}
return true;
}
return super.onOptionsItemSelected(item);
}
}
GalleryDetailFragment.java:
import com.sit.fth.model.GalleryDetail;
import com.sit.fth.util.APIServiceHandler;
import com.sit.fth.util.AppConstants;
import com.sit.fth.util.AppPromoPager;
public class GalleryDetailFragment extends BaseFragment implements
PromoPagerListener {
private TextView countView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
this.setHasOptionsMenu(true);
id = getArguments().getString("id");
name = getArguments().getString("name");
View view = inflater.inflate(R.layout.app_pager, null);
return view;
}
}
如果您知道如何解决这些问题,任何人都可以帮助我。谢谢。