in my application tablet and phone size are different, in phone i used listview for display data and , in tablet i used gridview for display data, so both code and design are different so its possible when apps start at first get screen display size as per display size on class call , if this app install in phone then phone class call and if install in tablet then tablet class call .. for phone i make activity and layout and for tablet i make different activity and layout. in i phone its possible ,screen resolution bound fetch and then class call so its possible in android. please help me. Thanks
Asked
Active
Viewed 326 times
0
-
if this app install in phone then phone class call and if install in tablet then tablet class call... this will be resolved by mentioned answer check it. – Syed Nazar Muhammad Aug 26 '14 at 11:05
-
2this is the correct answer to find device is a tablet or phone : http://stackoverflow.com/a/9308284/964741 – RajaReddy PolamReddy Aug 26 '14 at 11:05
-
Create separate views for tabs and phones.Then create separate classes for both and load the classes based on the device type. – Abx Aug 26 '14 at 11:18
-
@Abx yes, i make for phone and tablet different activity . but in my main activity how can i define and call activity.. if you have code or link then pls share with me. – Priyank Prajapati Aug 26 '14 at 11:40
1 Answers
1
This subject is discussed in the Android Training:
http://developer.android.com/training/multiscreen/screensizes.html#TaskUseSWQuali
If you read the entire topic, they explain how to set a boolean value in a specific value file (as res/values-sw600dp/):
<resources>
<bool name="isTablet">true</bool>
</resources>
Because the sw600dp qualifier is only valid for platforms above android 3.2. If you want to make sure this technique works on all platforms (before 3.2), create the same file in res/values-xlarge folder:
<resources>
<bool name="isTablet">true</bool>
</resources>
Then, in the "standard" value file (as res/values/), you set the boolean to false:
<resources>
<bool name="isTablet">false</bool>
</resources>
Then in you activity, you can get this value and check if you are running in a tablet size device:
boolean tabletSize = getResources().getBoolean(R.bool.isTablet);
if (tabletSize) {
Intent i = new(context, TabletActivity.class);
startActivity(i);
} else {
Intent i = new(context, MobileActivity.class);
startActivity(i);
}

Archit Jain
- 487
- 1
- 3
- 12
-
Hey Archit Thanks For Your Reply But this is only Layout change. i make Two main Activity one for tablet and second for phone. so first screen size Resolution get and as per screen size activity(class) call. So its possible? – Priyank Prajapati Aug 27 '14 at 05:58
-
yes you can do with that with the above activity. Lets say you got one activity in which you apply the above code (lets say activity name is `ChooseActivity.java`). and in if else statement if(tabletsize) then call Intent to your activity for Tablets( Lets say `TabletActivity.java`) and in else statement set Intent for Mobiles(Lets say `MobileActivity.java`). I edited my answer accordingly. – Archit Jain Aug 27 '14 at 11:44