其他分享
首页 > 其他分享> > frag点击activity

frag点击activity

作者:互联网

import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioGroup;

import com.bawei.moni.base.BaseActivity;
import com.bawei.moni.frag.Frag01;
import com.bawei.moni.frag.Frag02;

public class MainActivity extends BaseActivity {

private RadioGroup radio_group;
private Frag01 frag01;
private Frag02 frag02;
private FragmentManager manager;

@Override
protected void initData() {
    frag01 = new Frag01();
    frag02 = new Frag02();
    manager = getSupportFragmentManager();
    final FragmentTransaction transaction = manager.beginTransaction();
    transaction.add(R.id.frag,frag01)
            .add(R.id.frag,frag02)
            .show(frag01)
            .hide(frag02).commit();
    radio_group.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            FragmentTransaction transaction1 = manager.beginTransaction();
            switch (checkedId){
                case R.id.rb1:
                    transaction1.show(frag01)
                            .hide(frag02);
                    break;
                case R.id.rb2:
                    transaction1.show(frag02)
                            .hide(frag01);
                    break;
            }
            transaction1.commit();
        }
    });
}

@Override
protected void initView() {
    radio_group = findViewById(R.id.radio_group);
}

@Override
protected int LayoutId() {
    return R.layout.activity_main;
}

}

标签:frag,frag02,frag01,group,点击,activity,import,android,id
来源: https://blog.csdn.net/weixin_43241892/article/details/89060091