Question

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
Was it helpful?

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

OTHER TIPS

Just add the following statement to use LayoutParams with LinearLayout:

import android.widget.LinearLayout;

and then you can easily write the following code:

LinearLayout ll1;    
LayoutParams params1;

/*Creating a linear layout*/

ll1=new LinearLayout(this);
ll1.setOrientation(LinearLayout.VERTICAL);
/*set the width and height of the linear layout*/

params1=new LayoutParams(LayoutParams.MATCH_PARENT,    LayoutParams.MATCH_PARENT);
setContentView(ll1,params1);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top