0

can any one tell me it is possible to show different number of columns in listview

For Example:- when i see listview in portrait mode it shows 3 columns and when i see listview in landscape mode it shows 4 columns . i try to do it but my solutions doesn't work for me , i define to different layout for protrait in layout folder and landscape in layout-land folder but it doesn't seens to work for me .

Can any one tell me is it possible to achive this . 

And one More thing it possible to execute some code by checking 

For Example:-  if(this is android phone){

                  execute this code;
                 }

                if(this is android tablet){

                        execute this code;
                     }

 like iphone and ipad developer do 

                   if(this is iphone )
                   {
                    execute this code ;
                      }



                   if(this is ipad )
                   {
                    execute this code ;
                      }

because i same application is used in both phone and tablet and some one wants to show different things in phones and different in tablets .

Thanks in advance
5hssba
  • 8,079
  • 2
  • 33
  • 35
Sachin Gurnani
  • 2,444
  • 7
  • 36
  • 45

3 Answers3

0

Try this below link for tutorial

http://www.technotalkative.com/android-multi-column-listview/

Thanks..!

Dinesh
  • 6,500
  • 10
  • 42
  • 77
  • thanks for replying but i dont want this , i want same listview with different numbers of columns like when i use my app i portrait mode it shows 3 columns and in landscape it shows 4 columns . – Sachin Gurnani Apr 20 '12 at 10:58
0
 DisplayMetrics metrics = context.getResources().getDisplayMetrics();
 int width = metrics.widthPixels;
 int height = metrics.heightPixels;

this gives the dimensions of the screen and based on these values you can determine if it is a tablet.. See this link to know how to get dimensions of your device

Community
  • 1
  • 1
5hssba
  • 8,079
  • 2
  • 33
  • 35
0

Create more layouts with same name in /res/layout

After selecting root element click "Next" and then choose one of the Available qualifiers (orientation) and define listView with its properties.

vtuhtan
  • 1,056
  • 7
  • 18