最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定

關(guān)于activity跳入Fragment的方法

標(biāo)簽:
Android

1.所先在要跳的activity中布局最后添加FrameLayout 并且要设置android:layout_width="match_parent" android:layout_height="match_parent"和android:id="@+id/mainLayout"。

2.在该activity中声明要跳入的Fragment 初始化;然后在OnClickListener实现跳转,比如showFragment();里面还可以放参数showFragment(String orderID, double totalPrice);大概就可以了,注重要的是下面:

3.废话少说直接上代码。。。。。代码呢。。。

4.代码没有命有一条要不要。

5.强调,一定要记得要在activity布局最后写上

<FrameLayout

        android:id="@+id/mainLayout"

        android:layout_width="match_parent"

        android:layout_height="match_parent"

        ></FrameLayout>

下面是activity主要代码(点击按钮跳入fragment中),其中ChooseToPayFragmentManager是Fragment类

public class OtherMainActivity extends AppCompatActivity {

    ChooseToPayFragmentManager toPayFragmentManager;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_other_main);

        initView();

    }

    private void initView() {

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

        fagment.setOnClickListener(fragmentClick);

    }

    private View.OnClickListener fragmentClick = new View.OnClickListener() {

        @Override

        public void onClick(View v) {

            showFragment();

        }

    };

    private void showFragment() {

        if (toPayFragmentManager != null)

            return;

        toPayFragmentManager = new ChooseToPayFragmentManager();

        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        transaction.add(R.id.mainLayout, toPayFragmentManager);//这里要引用布局中的FrameLayout,也就是上面强调。

        transaction.commit();

    }

}

代码就这么多。我也是初学者,然后写的不好还不要望大家笑话,熟话说开头万事难。。。。其实我是一个很浮躁的人啦。我也希望自己通过写博客的方式能锻炼自己。

原文链接:http://www.apkbus.com/blog-455907-59888.html

點擊查看更多內(nèi)容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優(yōu)質(zhì)文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學(xué)習(xí),寫下你的評論
感謝您的支持,我會繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學(xué)

大額優(yōu)惠券免費領(lǐng)

立即參與 放棄機會
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號

舉報

0/150
提交
取消