lior
lior

Reputation: 152

view.post not executing run()

I have an app that works fine,but a year after no one touched it,i decided to do a comeback,but iv'e encountered a problem.running the app on android api 24 and after,the app just doesn't execute the view.post() with the run() in it,inside the onCreateView() .the app doesn't even crash,it's working,but with the missing ui.
i have done some debugging, and it just skips that for some reason.i used to think it was a thread problem,but now i don't know anymore. here is the class:

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);

  }
}

on api 23,for example,the code runs perfectly,and these two lines work fine:

ui.addUtilitiesToLayout((LinearLayout) getActivity().findViewById(R.id.moreLayout), false);
ui.addCategoriesToLayout((LinearLayout) getActivity().findViewById(R.id.categLayout), rowLength);

this is what i find weird:

l.post(new Runnable() {

it just skips that. it's just really annoying. i would really thank you for any help

Upvotes: 0

Views: 312

Answers (1)

Blackbelt
Blackbelt

Reputation: 157457

the problem lies on this line

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

it should be

return l;

inflater.inflate returns a new view every time gets called. What your onCreateView is returning is different from what you are posting on

Upvotes: 1

Related Questions