改变片段查看 [英] change Fragment View

查看:142
本文介绍了改变片段查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个片段的应用程序。它工作正常。

I have an app with fragments. It works fine.

其中的片段有一个按钮,当pressed我想改变的看法。

One of the fragments has a button, and when pressed I want to change the view.

public class BikeRecap extends Fragment {

public static Activity activity;
public static Context context;


/** Called when the activity is first created. */


public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    activity = getActivity();
    context = activity.getApplicationContext();

    View view = inflater.inflate(R.layout.bike_recap, container, false);        

    ImageButton details = (ImageButton) item.findViewById(R.id.details);


    details.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
              OpenNewView();
          }
    });

    return view;
}

OpenNewView()应改变视图,因此,用户在同一标签,但内容不同

OpenNewView() should change the view, so, the user is in the same tab, but the content is different

这可能吗?

推荐答案

您不能有一个片段内的片段。

You can't have a fragment inside a fragment.

试试这个code:

FragmentManager fragmentManager2 = getFragmentManager();
FragmentTransaction fragmentTransaction2 = fragmentManager2.beginTransaction();
DetailFragment fragment2 = new DetailFragment();
fragmentTransaction2.addToBackStack("abc");
fragmentTransaction2.hide(BikeRecap.this);
fragmentTransaction2.add(android.R.id.content, fragment2);
fragmentTransaction2.commit();

这篇关于改变片段查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆