Search code examples
android-layoutlayoutparamsresolve

what to import to resolve "LayoutParams cannot be resolved to a variable"?


I am getting error LayoutParams cannot be resolved to a variable on a line of code which is as follows tv.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 0.1f));
When i press ctrl+shift+o to import necessary pacakges i get a lot of versions of the package as options. I am confused which one should do the job. here are the options i get

after importing import android.app.ActionBar.LayoutParams; is still get error

The constructor AbsListView.LayoutParams(int, int, float) is undefined

Solution

  • It can be solved by importing [any layout].LayoutParams eg. import android.widget.GridLayout.LayoutParams; Although its not clear to me what should be the criteria to choose which package to import. To solve the problem

    the constructor AbsListView.LayoutParams(int, int, float) is undefined
    

    make sure the third argument is also an "int" it should be :

    LayoutParams cannot be resolved to a variable on a line of code which is as follows tv.setLayoutParams(new GridView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, 1));