沒有報錯,但為什么會停止??
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();
? ?}
}
最后運行的時候會崩潰。。
2016-08-21
你那些fragment是怎么寫的
2016-09-20
我和你一樣的問題,你那個現在弄好了嗎???