我试图给我的一个碎片充气。但是,片段不会出现在autosuggest中。所以我手动输入了片段的名称。通过这样做,片段名称以红色文本颜色显示,并且红色波浪线显示在所有类名称下面。但是,当我运行应用程序时,它运行完美,没有任何错误。
我有三个片段:fragment_dynamic_android.xml
,fragment_dynamic_windows.xml
和fragment_dynamic_ios.xml
。
我可以用fragment_dynamic_android.xml
方法在AndroidFragment.java
类中膨胀onCreateView
。
但是当我试图在fragment_dynamic_windows.xml
的WindowsFragment.java
方法上膨胀onCreateView
时。
红色文本颜色正在显示
查看rootView = inflater.inflate(R.layout.fragment_dynamic_windows,container,false);
应用程序运行没有任何错误。
package app.tab.simple.fragmenttut;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class WindowsFragment extends Fragment {
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_dynamic_windows, container, false);
return rootView;
}
}
经过一番挫折之后,关闭电脑并开始做一些事情。又来了,打开了项目,错误消失了。不知道为什么android studio表现得那样。