Im trying to inflate a view depending on screen size so I can use different layouts
I have tried the following
double screen_size = 8
if screen_size >= 10 {
layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflator.inflate(R.layout.mylist, parent, false);
}
if screen_size >= 5 && screen_size <=9){
layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
}
TextView textview1 = (TextView) row.findViewById(R.id.textView1);
I get an error on the Textview
saying row
cannot be resolved even tho the if
statement is being run
If I change to
double screen_size = 8
if screen_size >= 10 {
layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
}
if screen_size >= 5 && screen_size <=9){
layoutInflator =(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View row = layoutInflator.inflate(R.layout.mylist2, parent, false);
}
View row = layoutInflator.inflate(R.layout.mylist, parent, false);
TextView textview1 = (TextView) row.findViewById(R.id.textView1);
it runs fine but always runs layout mylist
instead of mylist2
Any ideas where im going wrong
Any help appreciated
Mark
Your not casting it to View :
Change the line to above line wherever your inflating views.