Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 360
Sunil Kumar Avatar asked Nov 01 '22 05:11

Sunil Kumar


2 Answers

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));
like image 73
Sunil Kumar Avatar answered Dec 20 '22 01:12

Sunil Kumar


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);
like image 23
Sumeet Avatar answered Dec 20 '22 02:12

Sumeet