Android 如何在FrameLayout中启动活动
我在一个框架布局中使用片段,但由于一些问题,我想在该框架布局中启动一个活动。我搜索了很长一段时间,我得到的只是标签规格和所有这些。我只是想在所有片段都打开的框架布局中开始活动 下面是我如何打开我的片段和消息活动Android 如何在FrameLayout中启动活动,android,android-framelayout,Android,Android Framelayout,我在一个框架布局中使用片段,但由于一些问题,我想在该框架布局中启动一个活动。我搜索了很长一段时间,我得到的只是标签规格和所有这些。我只是想在所有片段都打开的框架布局中开始活动 下面是我如何打开我的片段和消息活动 private void displayView(int position) { switch (position) { case 0: fragment = new MyFeedsFragment(); break; case 1
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");
}
}
我希望消息活动以与片段相同的布局打开
我怎么能这样做
非常感谢您的帮助。请尝试以下代码:
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);
请尝试以下代码:
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);
在android中,只有一个活动可以激活。。。如果您有带片段的活动,并从其中一个片段运行另一个活动,则实际活动将暂停。您只能在实际活动中运行另一个片段或更改视图,并调用自己的refresh()方法…在android中,只有一个活动可以处于活动状态。。。如果您有带片段的活动,并从其中一个片段运行另一个活动,则实际活动将暂停。您只能在实际活动中运行另一个片段或更改视图,并调用自己的refresh()方法…改用布局充气器,您不能在活动中打开活动。
LayoutInflator infltor=(LayoutInflator)context.getSystemService(context.layout\u inflator\u Service)代码>查看视图=充气(R.layout.your\u activity\u视图,空)代码>然后使用此视图显示到您的FrameLayout中,并执行此活动类中的所有活动代码。改用布局充气器,您无法在活动内打开活动。LayoutFlator infltor=(LayoutFlator)context.getSystemService(context.layout\u inflator\u Service)代码>查看视图=充气(R.layout.your\u activity\u视图,空)代码>然后使用此视图显示到您的FrameLayout中,并执行此活动类中的所有活动代码。什么是R.layout.top_栏??这是您要在其中充气的充气机视图(活动布局)。什么是R.layout.top_栏??这是您要在其中充气的充气机视图(活动布局)。