91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

Fragment (一)

發布時間:2020-07-25 20:52:04 來源:網絡 閱讀:558 作者:jdijfijf 欄目:移動開發

MainActivity:

package com.example.fragmentmanage;


import android.app.Activity;

import android.app.FragmentManager;

import android.app.FragmentTransaction;

import android.os.Bundle;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;


public class MainActivity extends Activity implements OnClickListener {


private Button btn1;

private Button btn2;


private FirstFragment firstFragment;

private SencondFragment sencondFragment;


@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

initView();

setDefaultFragment();

}


private void initView() {

btn1 = (Button) findViewById(R.id.btn1);

btn2 = (Button) findViewById(R.id.btn2);

btn1.setOnClickListener(this);

btn2.setOnClickListener(this);

}


private void setDefaultFragment() {

FragmentManager manager = getFragmentManager();

FragmentTransaction transaction = manager.beginTransaction();

firstFragment = new FirstFragment();

transaction.replace(R.id.fragme_layout, firstFragment);

transaction.commit();

}


@Override

public void onClick(View arg0) {

FragmentManager manager = getFragmentManager();

FragmentTransaction transaction = manager.beginTransaction();


switch (arg0.getId()) {

case R.id.btn1:

if (firstFragment == null) {

firstFragment = new FirstFragment();

}

transaction.replace(R.id.fragme_layout, firstFragment);

break;

case R.id.btn2:

if (sencondFragment == null) {

sencondFragment = new SencondFragment();

}

transaction.replace(R.id.fragme_layout, sencondFragment);

break;


default:

break;


}

transaction.commit();

}


}

activity_main:


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

    xmlns:tools="http://schemas.android.com/tools"

    android:layout_width="match_parent"

    android:layout_height="match_parent"

    android:paddingBottom="@dimen/activity_vertical_margin"

    android:paddingLeft="@dimen/activity_horizontal_margin"

    android:paddingRight="@dimen/activity_horizontal_margin"

    android:paddingTop="@dimen/activity_vertical_margin"

    tools:context=".MainActivity" >


    <LinearLayout

        android:layout_width="match_parent"

        android:layout_height="wrap_content"

        android:orientation="horizontal" >


        <Button

            android:id="@+id/btn1"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="btn1" />


        <Button

            android:id="@+id/btn2"

            android:layout_width="wrap_content"

            android:layout_height="wrap_content"

            android:layout_weight="1"

            android:text="btn2" />

    </LinearLayout>


    <FrameLayout

        android:id="@+id/fragme_layout"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content" />


</RelativeLayout>


FirstFragment:


package com.example.fragmentmanage;


import android.app.Fragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;


public class FirstFragment extends Fragment {

@Override

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

return inflater.inflate(R.layout.fragment_first, null);

}

}

SencondFragment:

package com.example.fragmentmanage;


import android.app.Fragment;

import android.os.Bundle;

import android.view.LayoutInflater;

import android.view.View;

import android.view.ViewGroup;


public class FirstFragment extends Fragment {

@Override

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

return inflater.inflate(R.layout.fragment_first, null);

}

}


向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

千阳县| 泉州市| 余姚市| 枞阳县| 汉寿县| 成武县| 福海县| 寻乌县| 峨山| 惠州市| 忻州市| 延寿县| 隆子县| 隆化县| 林口县| 宝丰县| 淮南市| 南汇区| 玉屏| 扬中市| 固安县| 马龙县| 常德市| 沁水县| 斗六市| 元阳县| 贵溪市| 东兰县| 修水县| 五华县| 连南| 嘉善县| 随州市| 白河县| 芮城县| 上林县| 江安县| 杭锦旗| 吉安市| 黑水县| 信宜市|