我在框架布局中使用片段,但由于某些问题,我想在Frame布局中启动一个Activity。我正在寻找这个已经有很长一段时间了,我得到的就是Tab规格所有这一切。我只想在我的Frame布局中启动活动,其中所有片段都打开
这是我如何打开我的片段和消息活动
private void displayView(int position) {
switch (position) {
case 0:
fragment = new MyFeedsFragment();
break;
case 1:
fragment = new MyPrivatePostsFragment();
break;
case 2:
fragment = new MyProfileFragment();
break;
case 3:
fragment = new PeopleFragment();
break;
case 4:
Intent intent = new Intent(getApplicationContext(),
MessagesActivity.class);
startActivity(intent);
break;
case 5:
fragment = new FavouritesFragment();
break;
case 6:
fragment = new CreditsFragment();
break;
case 7:
fragment = new SettingsFragment();
break;
case 8:
fragment = new AboutThisAppFragment();
break;
case 9:
fragment = new ContactUsFragment();
break;
case 10:
fragment = new LogOutFragment();
store.setLoginStatus(null);
break;
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager
.beginTransaction();
if (!fragment.isAdded()) {
fragmentTransaction.add(R.id.frame_container, fragment)
.addToBackStack(null).commit();
} else {
fragmentTransaction.show(fragment);
}
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(navMenuTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e("Main Activity", "error in creating fragment");
}
}
我希望Message Frag在我的片段中以相同的布局打开 我怎么能这样做?
任何帮助将不胜感激..
答案 0 :(得分:4)
在android中只有一个活动可以处于活动状态...如果您有片段活动并从其中一个片段运行另一个活动,则实际活动将暂停。您只能在实际的Activity中运行另一个Fragment或更改您的视图并调用您自己的refresh()方法......
答案 1 :(得分:0)
尝试以下代码:
LayoutInflater inflater =(LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.your_inflator_view, null);
Intent i = new Intent();
i.setClass(view.getContext(), MessageActivity.class);
view.getContext().startActivity(i);