I'm trying to create a LinearLayout in another activity called MainFragment. Inside onCreate function I'm using the line
LinearLayout parent = new LinearLayout(MainFragment.this);
using this shows same error
error:
LinearLayout (andorid.content.Context) in LinearLayout cannot be applied to (com.example.name.nav_bar.MainFragment)
If I try the code in MainActivity it works fine.
LinearLayoutconstructor needs aContext, while aFragmentis not a subclass ofContext, andActivityis a subclass ofContext.LinearLayout parent = new LinearLayout(getContext);LinearLayout parent = new LinearLayout(getActivity);