FragmentTransaction.add()

时间:2015-03-07 03:44:24

标签: java android android-fragments

我遇到了add()方法的问题,该方法无法读取参数它无法读取我的BlankFragment类作为片段,而是读取包名称后跟类名称& #39;是我的代码

package com.example.ucon.myapplication;

import android.app.Fragment;
import android.support.v7.app.ActionBarActivity;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;


public class MainActivity extends ActionBarActivity {

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        if (findViewById(R.id.fragment_container) != null){
            if (savedInstanceState != null) {
                return;
            }
            BlankFragment firstFragment = new BlankFragment();
            firstFragment.setArguments(getIntent().getExtras());
            getSupportFragmentManager().beginTransaction().add(R.id.fragment_container, firstFragment).commit();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

我解决了我必须导入的问题

android.support.v4.app.Fragment

而不是

android.app.Fragment 

在片段类