没有报错,但为什么会停止??
package com.example.myapplication;
import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Main3Activity extends Activity {
private Button button;
private Fragment fragment;
private boolean flag =true;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
button = (Button) findViewById(R.id.transform);
init();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
android.app.FragmentManager fragM =getFragmentManager();
FragmentTransaction bgfragmentT =fragM.beginTransaction();
if(flag){
fragment4 frag4=new fragment4();
bgfragmentT.replace(R.id.layout,frag4);
flag=false;
}else {
fragment3 frag3=new fragment3();
bgfragmentT.replace(R.id.layout,frag3);
flag=true;
}
bgfragmentT.commit();
}
});
}
private void init() {
fragment3 frag3= new fragment3();
android.app.FragmentManager fragmentmanager =getFragmentManager();
FragmentTransaction fragmentTransaction =fragmentmanager.beginTransaction();
fragmentTransaction.add(R.id.layout,frag3);
fragmentTransaction.commit();
}
}
最后运行的时候会崩溃。。