我试图有一个导航抽屉,让我选择不同类型的片段。我实现了一个 Runnable() 线程,因此当片段发生变化时过渡会更加平滑。但是,在我实现之后,它不会在开始时加载默认片段,这意味着它将显示为空白,我必须单击导航抽屉才能在 srart 上显示一些内容。
我希望它能够在应用程序开始时显示菜单上的第一项(菜单 0 )
这是一些代码片段
private class DrawerItemClickListener implements
ListView.OnItemClickListener {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
selectItem(position);
}
}
private void selectItem(final int position) {
mPendingRunnable = new Runnable() {
@Override
public void run() {
// update the main content by replacing fragments
changeFragment(position);
}
};
// update selected item and title, then close the drawer
// update the main content by replacing fragments
// update selected item and title, then close the drawer
mDrawerList.setItemChecked(position, true);
setTitle(mPAGETitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
}
private void changeFragment(final int position)
{
Fragment fragment = new PageFragment(MainActivity.this);
Bundle args = new Bundle();
args.putInt(PageFragment.ARG_PAGE_NUMBER, position);
fragment.setArguments(args);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame,
fragment).commit();
fragmentChanged =true;
}
public void onDrawerClosed(View view) {
getActionBar().setTitle(mTitle);
invalidateOptionsMenu(); // creates call to
//
onPrepareOptionsMenu()
if (mPendingRunnable != null) {
Handler mHandler = new Handler();
mHandler.post(mPendingRunnable);
mPendingRunnable = null;
}
progress = ProgressDialog.show(MainActivity.this,
"Downloading Data",
"Please wait while Data are downloaded");
progress.setCancelable(false);
progress.isIndeterminate();
progress.show();
}