Android view.post未执行run()

Android view.post未执行run(),android,android-layout,android-fragments,android-activity,android-scrollview,Android,Android Layout,Android Fragments,Android Activity,Android Scrollview,我有一个很好用的应用程序,但一年后没人碰它,我决定做一个测试 卷土重来,但iv'e遇到了一个问题。在android api 24及之后运行应用程序时,应用程序只是不在onCreateView中执行view.post .该应用程序甚至没有崩溃,它正在工作,但缺少用户界面。 我做了一些调试,但出于某种原因,它跳过了。我以前认为这是一个线程问题,但现在我不知道了。 下面是课堂: public class CategoriesFragment extends Fragment { final Strin

我有一个很好用的应用程序,但一年后没人碰它,我决定做一个测试 卷土重来,但iv'e遇到了一个问题。在android api 24及之后运行应用程序时,应用程序只是不在onCreateView中执行view.post .该应用程序甚至没有崩溃,它正在工作,但缺少用户界面。 我做了一些调试,但出于某种原因,它跳过了。我以前认为这是一个线程问题,但现在我不知道了。 下面是课堂:

public class CategoriesFragment extends Fragment {
final String dbname = "app";
final String tbname = "categories";
DynamicUI ui;
int rowLength = 3;
final int dbver = 1;
public CategoriesFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

    final ScrollView l = (ScrollView) inflater.inflate(R.layout.fragment_categories_grid, container, false);
    l.post(new Runnable() {
        @Override
        public void run() {
            ui.addUtilitiesToLayout((LinearLayout) getActivity().findViewById(R.id.moreLayout), false);
            ui.addCategoriesToLayout((LinearLayout) getActivity().findViewById(R.id.categLayout), rowLength);
            // code you want to run when view is visible for the first time
        }
    });
    ui = new DynamicUI(getActivity(),DatabaseHelper.RIGHTS);
    return inflater.inflate(R.layout.fragment_categories_grid, container, false);

  }
}
例如,在api 23上,代码运行良好,这两行工作正常:

ui.addUtilitiesToLayout((LinearLayout) getActivity().findViewById(R.id.moreLayout), false);
ui.addCategoriesToLayout((LinearLayout) getActivity().findViewById(R.id.categLayout), rowLength);
这就是我觉得奇怪的地方:

l.post(new Runnable() {
它只是跳过了这个。 这真的很烦人。
我非常感谢您的帮助

问题出在这条线上

return inflater.inflate(R.layout.fragment_categories_grid, container, false);
应该是

return l;
每次调用充气器时,充气器都返回一个新视图。onCreateView返回的内容与您发布的内容不同