android - If else statement conflict for device orientation -
android - If else statement conflict for device orientation -
i created app retrieves web service api data. able display info in list view. works fine except want utilize spinner instead of listview when in portrait mode. created code 2 xml files: 1 in portrait spinner , 1 in landscape listview , code checks these orientation changes unfortunately app crashes. can explain going on?
@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { if(getresources().getconfiguration().orientation == configuration.orientation_landscape){ view view = inflater.inflate(r.layout.master_fragment, container, false); // loads available info in receipelist master fragment. arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_1, receipelist); setlistadapter(adapter); homecoming view; }else { view view = inflater.inflate(r.layout.master_fragment_spinner, container, false); arrayadapter<string> adapter = new arrayadapter<string>(getactivity(), android.r.layout.simple_list_item_1, receipelist); setlistadapter(adapter); homecoming view; } }
you don't need test orientation, set xml file protrait in /res/layout
, xml file landscape in /res/layout-land
, android load right xml
android orientation
Comments
Post a Comment