简体   繁体   English

当我使用自动完成挂钩框架布局时,Android Studio 3.6.1 错误

[英]Android Studio 3.6.1 error when i hook frame layout with autocomplete

Hello I just want to switch from a fragment to another using a button.您好,我只想使用按钮从一个片段切换到另一个片段。 Nothing difficult... the code works well but I have spent a lot of time because Android goesto error if I hook frameLayout with autocompile.没什么难的......代码运行良好,但我花了很多时间,因为如果我用自动编译挂钩 frameLayout,Android 会出错。 I'm explaining better:我解释得更好:

package com.example.fragcookbook;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;

public class MainActivity extends AppCompatActivity {

    FragmentOne mFragmentOne;
    FragmentTwo mFragmentTwo;
    int showingFragment=0;

    @Override
    protected void onCreate ( Bundle savedInstanceState ) {
        super.onCreate (savedInstanceState);
        setContentView (R.layout.activity_main);
        mFragmentOne = new FragmentOne();
        mFragmentTwo = new FragmentTwo();
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        fragmentTransaction.add(R.id.frameLayout, mFragmentOne);
        fragmentTransaction.commit();
        showingFragment=1;

    }
    public void switchFragment(View view) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        if (showingFragment==1) {
            fragmentTransaction.replace(R.id.frameLayout, mFragmentTwo);
            showingFragment = 2;
        } else {
            fragmentTransaction.replace(R.id.frameLayout, mFragmentOne);
            showingFragment=1;
        }
        fragmentTransaction.commit();
    }

In all rows where you see R.id.frameLayout i have to handly write frameLayout..... Android colors it red but It works...在您看到 R.id.frameLayout 的所有行中,我必须手动编写 frameLayout ..... Android colors 它是红色的,但它可以工作...... 在此处输入图像描述

But if i choose the resource with autocompile...但是,如果我选择具有自动编译功能的资源... 在此处输入图像描述

...when i run app Android gives me this error.... ...当我运行应用程序 Android 给我这个错误.... 在此处输入图像描述

Why?为什么? is not best practice use autocompile?不是最佳实践使用自动编译吗? Thanks in advance提前致谢

Try this may will help you.Go to "File" -> "Invalidate Caches...", and select "Invalidate and Restart" option to fix this.试试这个可能会对你有所帮助。Go 到“文件”->“无效缓存...”,以及 select“无效并重新启动”选项来解决这个问题。

Or或者

Restar you android studio and emulator重新启动你 android 工作室和仿真器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 工具栏未显示在 Android Studio 3.6.1 的布局编辑器中 - Toolbar not showing in the layout editor of Android Studio 3.6.1 Android Studio 3.6.1,未显示布局设计视图 - Android Studio 3.6.1, Layout Design View not showing 在 Android Studio(3.6.1) 中创建空活动时未解决的参考 - Unresolved reference when I create Empty Activity in Android Studio(3.6.1) Android Studio 3.6.1 的布局编辑器中缺少标记为“设计”和“文本”的选项卡 - Tabs labeled "Design" and "Text" missing in the layout editor in Android Studio 3.6.1 android studio 3.6.1 中未显示布局预览工具栏 - Layout Preview toolbar doesn't show in android studio 3.6.1 将 Android Studio 3.5 升级到 3.6.1 后编译应用程序时出错 - Error compiling app after upgrade Android Studio 3.5 to 3.6.1 Android Studio 3.6.1 构建问题 - Android studio 3.6.1 build issue BuildConfig 在 Android Studio 3.6.1 中不起作用 - BuildConfig is not working in Android studio 3.6.1 当我在 Android Studio 3.6.1 中运行项目时,为什么会出现“文件被另一个进程使用”错误? - Why do I get “file is used by another process” errors when I run the project within Android Studio 3.6.1? 我收到 android 工作室布局和等级错误 - I get android studio layout and grade error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM