【问题标题】:cannot resolved method getChildFragmentManager()无法解决方法 getChildFragmentManager()
【发布时间】:2016-11-14 16:01:09
【问题描述】:

错误:只有在 android.support.v4.app.Fragment 中提供 getChildFragmentManager() 方法时才能使用“childFragmentManager”参数,请更新您的支持库版本。

我已经在我的 gradle 中编译了 'com.android.support:support-v4:24.2.0'。我的代码喜欢;

 import android.support.v4.app.Fragment;
 import org.androidannotations.annotations.*;
 import org.androidannotations.annotations.sharedpreferences.Pref;
.
.

@EFragment(R.layout.fragment_main)
public class MainFragment extends Fragment {
@Pref
ApplicationSettings_ applicationSettings;
@ViewById(R.id.bot)
public LinearLayout bot;
@ViewById(R.id.center)
public LinearLayout center;
@Bean
UIItemGenerator uiItemGenerator;
@SystemService
LayoutInflater layoutInflater;
@FragmentById(value = R.id.contentFragment,childFragment = true)
public ContentFragment contentFragment;

public MainFragment() {
}

@Click(R.id.imagebutton_ribbon)
public void ribbonClick(View view) {
    view.setVisibility(View.GONE);
}

.
.
.
@AfterViews
public void afterViews() {
    if (contentFragment == null)
        contentFragment = (ContentFragment) this.getChildFragmentManager().findFragmentById(R.id.contentFragment);
    for (int j = 0; j < bot.getChildCount(); j++) {
        bot.getChildAt(j).setSelected(false);
    }
    for (int j = 0; j < top.getChildCount(); j++) {
        top.getChildAt(j).setSelected(false);
    }
    ll_home.setSelected(true);
    ll_allrooms.setSelected(true);
    initUI();
    contentFragment.generateContent(-1, -1);
    imagebutton_top_rightarrow.setSelected(true);
    imagebutton_bot_rightarrow.setSelected(true);

【问题讨论】:

    标签: java android android-support-library android-studio-2.2


    【解决方案1】:

    getChildFragmentManager() 是 Fragment 上的一个方法并检查您的导入语句

    import android.support.v4.app.FragmentManager;
    

    我认为你正在使用 AppCompatActivity(FragmentActivity 的子类),你必须使用这个

    getSupportFragmentManager()
    

    【讨论】:

    • 他扩展了 Fragment 而不是 Fragment Activity,请在发布答案之前仔细检查问题。
    猜你喜欢
    • 2016-05-07
    • 2012-10-11
    • 1970-01-01
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    相关资源
    最近更新 更多