zoukankan      html  css  js  c++  java
  • Fragment

    // 创建一个Fragment->   PlaceholderFragment

    public class PlaceholderFragment extends Fragment { // android.support.v4.app.Fragment;
    
        public PlaceholderFragment() {}
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragement_main, container, false);
    
            rootView.findViewById(R.id.btnShowAnotherFrament).setOnClickListener(new View.OnClickListener(){
                public void onClick(View v) {
             // 启动另外一个 Fragment getFragmentManager().beginTransaction() .addToBackStack(
    null) // 添加后退栈 不然的后退的话没有效果 .replace(R.id.container, new AnotherFragment()) // 在这个容器里面替换 新的Fragment .commit(); } }); rootView.findViewById(R.id.btnStartSliderActivity).setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v) { getFragmentManager().popBackStack(); } }); return rootView; } }

    PlaceholderFragment对应的视图

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity$PlaceholderFragment">
    
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="呈现另一个Fragement"
            android:id="@+id/btnShowAnotherFrament" />
    </LinearLayout>

    // 2. 从主 MainActivity中加载PlaceholderFragment

     protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
            if (savedInstanceState == null) {
                getSupportFragmentManager().beginTransaction().add(R.id.container, new PlaceholderFragment())
                        .commit();
            }
            System.out.println("onCreate");
        }
  • 相关阅读:
    25、DataReaderWriter
    javascript 事件(基础)0831
    html 表单下拉列表框
    css
    getElementById的三个用法
    javascript原型对象prototype
    JS String类型
    javascript闭包及作用域
    JavaScript匿名函数
    Javascript表单(text,radio,checkbox等)验证大全0830
  • 原文地址:https://www.cnblogs.com/shaoshao/p/5866928.html
Copyright © 2011-2022 走看看