Android: Multi Pane layout detail view appears by default -


in app, have requirement of multi payne layout. in layout, first fragment listview shows list of items. on click of list item, detail view open on right hand side of list item. but, in case, when run app on tablet, detail view appears along listview default. while, want should appear on click of list item.

below code:

activity class:

public class orderactivity extends fragmentactivity implements     onorderselectedlistener { private static final string tag = "orderactivity";  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     log.d(tag, "oncreate called");     setcontentview(r.layout.order_details);      if (findviewbyid(r.id.fragment_container) != null) {         if (savedinstancestate != null) {             return;         }          orderlistfragment orderlistfragment = new orderlistfragment();         orderlistfragment.setarguments(getintent().getextras());         getsupportfragmentmanager().begintransaction()                 .add(r.id.fragment_container, orderlistfragment).commit();     } }  @override public void onorderselected(int position) {     log.d(tag, "onorderselected called");     orderdetailfragment detailsfrag = (orderdetailfragment) getsupportfragmentmanager()             .findfragmentbyid(r.id.order_detail_fragment);      if (detailsfrag != null) {         if (!detailsfrag.isvisible()) {             detailsfrag.setuservisiblehint(true);             detailsfrag.updateorderview(position);         }     } else {         orderdetailfragment newfragment = new orderdetailfragment();         bundle args = new bundle();         args.putint(orderdetailfragment.arg_position, position);         newfragment.setarguments(args);;         fragmenttransaction transaction = getsupportfragmentmanager()                 .begintransaction();         transaction.replace(r.id.fragment_container, newfragment);         transaction.addtobackstack(null);         transaction.commit();     } } } 

list fragment

public class orderlistfragment extends listfragment { private static final string tag = "orderlistfragment"; onorderselectedlistener monorderselectedlistener;  public interface onorderselectedlistener {     public void onorderselected(int position); }  @override public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     log.d(tag, "oncreate called"); }  @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     log.d(tag, "oncreateview called");     return inflater.inflate(r.layout.order_list, null); }  @override public void onactivitycreated(bundle savedinstancestate) {     super.onactivitycreated(savedinstancestate);     log.d(tag, "onactivitycreated called");     arraylist<data> mdatalist = new arraylist<data>();     data mdata1 = new data("1", "11001", "08/07/2013", "gauge_run",             "dispatched", "terminal:", "rail terminal:", "new york",             "washington dc");     data mdata2 = new data("1", "11002", "08/07/2013", "gauge_run",             "dispatched", "terminal:", "rail terminal:", "new york",             "washington dc");     mdatalist.add(mdata1);     mdatalist.add(mdata2);     setlistadapter(new orderadapter(getactivity(),             r.layout.order_list_item, mdatalist)); }  @override public void onstart() {     super.onstart();     log.d(tag, "onstart called");     if (getfragmentmanager().findfragmentbyid(r.id.order_detail_fragment) != null) {         getlistview().setchoicemode(listview.choice_mode_single);     } }  @override public void onattach(activity activity) {     super.onattach(activity);     log.d(tag, "onattach called");     // makes sure container activity has implemented     // callback interface. if not, throws exception.     try {          monorderselectedlistener = (onorderselectedlistener) activity;     } catch (classcastexception e) {         throw new classcastexception(activity.tostring()                 + " must implement onheadlineselectedlistener");     } }  @override public void onlistitemclick(listview l, view v, int position, long id) {     log.d(tag, "onlistitemclicked");     monorderselectedlistener.onorderselected(position);     getlistview().setitemchecked(position, true); } } 

detail fragment

public class orderdetailfragment extends fragment { public final static string arg_position = "position"; int mcurrentposition = -1; private static final string tag = "orderdetailfragment"; @override public view oncreateview(layoutinflater inflater, viewgroup container,         bundle savedinstancestate) {     log.d(tag, "oncreateview called");     if (savedinstancestate != null) {         mcurrentposition = savedinstancestate.getint(arg_position);     }     return inflater.inflate(r.layout.acceptance_details, container, false); }  @override public void onstart() {     log.d(tag, "onstart called");     super.onstart();     bundle args = getarguments();     if (args != null) {         updateorderview(args.getint(arg_position));     } else if (mcurrentposition != -1) {         updateorderview(mcurrentposition);     } }  public void updateorderview(int position) {     log.d(tag, "updateorderview called");     /*      * textview article = (textview)      * getactivity().findviewbyid(r.id.article);      * article.settext(ipsum.articles[position]); btnnext = (button)      * getactivity().findviewbyid(r.id.btnnext);      * btnnext.setonclicklistener(this); mcurrentposition = position;      */ }  @override public void onsaveinstancestate(bundle outstate) {     log.d(tag, "onsaveinstancestate called");     super.onsaveinstancestate(outstate);     outstate.putint(arg_position, mcurrentposition); } } 

activity layout

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/white" android:orientation="horizontal" >  <com.dzo.dispatchcrude.driverapp.ui.headerbar     android:id="@+id/headerbar"     android:layout_width="match_parent"     android:layout_height="100dp"     android:layout_alignparenttop="true" > </com.dzo.dispatchcrude.driverapp.ui.headerbar>  <linearlayout     android:id="@+id/linorderview"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_below="@+id/headerbar"     android:baselinealigned="false"     android:orientation="horizontal" >      <fragment         android:id="@+id/order_list_fragment"         android:name="com.dzo.dispatchcrude.driverapp.ui.orderlistfragment"         android:layout_width="0dp"         android:layout_height="match_parent"         android:layout_weight="1" />      <fragment         android:id="@+id/order_detail_fragment"         android:name="com.dzo.dispatchcrude.driverapp.ui.orderdetailfragment"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_gravity="center"         android:layout_margin="30dp"         android:layout_weight="2" /> </linearlayout>  </relativelayout> 

list fragment layout

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >  <listview     android:id="@id/android:list"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:dividerheight="1dp" />  </linearlayout> 

order detail fragment

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="20dp" android:background="@drawable/corner_shape" android:orientation="vertical" >  <textview     android:id="@+id/txtheadertype"     android:layout_width="match_parent"     android:layout_height="70dp"     android:layout_marginbottom="-5dp"     android:background="@drawable/upper_corner"     android:gravity="center"     android:text="@string/acceptance_details"     android:textcolor="@android:color/white"     android:textsize="30sp"     android:textstyle="bold" />  <textview     android:id="@+id/txtheadersource"     android:layout_width="match_parent"     android:layout_height="70dp"     android:background="@drawable/rectangle"     android:gravity="center"     android:textsize="25sp"     android:textstyle="bold" />  <linearlayout     android:layout_width="match_parent"     android:layout_height="70dp"     android:gravity="center_vertical"     android:orientation="horizontal" >      <textview         android:id="@+id/txttruck"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:gravity="center_vertical"         android:paddingleft="15dp"         android:text="@string/truck"         android:textcolor="@color/text_color"         android:textsize="20sp"         android:typeface="sans" />      <spinner         android:id="@+id/truckspinner"         style="@android:style/widget.spinner"         android:layout_width="0dp"         android:layout_height="50dp"         android:layout_margin="10dp"         android:layout_weight="3"         android:background="@drawable/bg_edit_text"         android:gravity="center"         android:spinnermode="dropdown" /> </linearlayout>  <view     android:layout_width="match_parent"     android:layout_height="1dp"     android:background="@color/divider_color" />  <linearlayout     android:layout_width="match_parent"     android:layout_height="70dp"     android:gravity="center_vertical"     android:orientation="horizontal" >      <textview         android:id="@+id/txttrailor"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:gravity="center_vertical"         android:paddingleft="15dp"         android:text="@string/trailor"         android:textcolor="@color/text_color"         android:textsize="20sp" />      <spinner         android:id="@+id/trailorspinner"         style="@android:style/widget.spinner"         android:layout_width="0dp"         android:layout_height="50dp"         android:layout_margin="10dp"         android:layout_weight="3"         android:background="@drawable/bg_edit_text"         android:gravity="center"         android:spinnermode="dropdown" /> </linearlayout>  <view     android:layout_width="match_parent"     android:layout_height="1dp"     android:background="@color/divider_color" />  <linearlayout     android:layout_width="match_parent"     android:layout_height="70dp"     android:gravity="center_vertical"     android:orientation="horizontal" >      <textview         android:id="@+id/txttrailor2"         android:layout_width="0dp"         android:layout_height="wrap_content"         android:layout_weight="1"         android:gravity="center_vertical"         android:paddingleft="15dp"         android:text="@string/trailor2"         android:textcolor="@color/text_color"         android:textsize="20sp" />      <spinner         android:id="@+id/trailor2spinner"         style="@android:style/widget.spinner"         android:layout_width="0dp"         android:layout_height="50dp"         android:layout_margin="10dp"         android:layout_weight="3"         android:background="@drawable/bg_edit_text"         android:gravity="center"         android:spinnermode="dropdown" /> </linearlayout>  <view     android:layout_width="match_parent"     android:layout_height="1dp"     android:background="@color/divider_color" />  <button     android:id="@+id/btnaccept"     android:layout_width="match_parent"     android:layout_height="70dp"     android:layout_marginbottom="25dp"     android:layout_marginleft="15dp"     android:layout_marginright="15dp"     android:layout_margintop="25dp"     android:background="@drawable/input_button"     android:gravity="center"     android:text="@string/accept"     android:textcolor="@android:color/white"     android:textsize="30sp"     android:textstyle="bold" />  </linearlayout> 

i did gone through fragments basic demo given on android developer's site, couldn't figure out mistake.

try this

listview.setchoicemode(listview.choice_mode_single); listview.setitemchecked(0,false); 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -