Thursday 15 July 2010

Android fragments xml crash -



Android fragments xml crash -

i maintain getting crash when alter set content view xml layout , not sure whats wrong. programme supposed have 2 fragments, list view on left , webview on right when in landscape , list in portrait. sorry code, can not figure out going on.

here main activity

public class mainactivity extends activity { static final string logtag = mainactivity.class.getsimplename() + "_tag"; static resources mres = null; static fragmentmanager mfrgmntmngr = null; static mainactivity mthisact = null; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); fragmentmanager.enabledebuglogging(true); setcontentview(r.layout.activity_main_1view); mres = getresources(); mfrgmntmngr = getfragmentmanager(); mthisact = this; } static boolean isinlandscapeorientation() { homecoming mres.getconfiguration().orientation == configuration.orientation_landscape; } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } public void displaytwaintext(int mcurposition) { // todo auto-generated method stub if ( isinlandscapeorientation() ) { // check fragment shown, replace if needed. twaintitlewebviewfragment ttxtfrgmnt = (twaintitlewebviewfragment) mfrgmntmngr.findfragmentbyid(r.id.twain_title_list); if (ttxtfrgmnt == null || ttxtfrgmnt.getdisplayedtwainindex() !=mcurposition) // create new fragment show selection. ttxtfrgmnt = twaintitlewebviewfragment.newinstance(mcurposition); // execute transaction, replacing existing // fragment within frame new one. log.d(logtag, "about run fragmenttransaction..."); fragmenttransaction frag_trans = mfrgmntmngr.begintransaction(); frag_trans.setcustomanimations(r.animator.bounce_in_down, r.animator.fade_out); frag_trans.setcustomanimations(r.animator.bounce_in_down, r.animator.slide_out_right); frag_trans.replace(r.id.list, ttxtfrgmnt); frag_trans.commit(); } } else { // otherwise need launch new activity display // dialog fragment selected text. intent intent = new intent(); intent.setclass(mthisact, twaintitleviewactivity.class); intent.putextra(mres.getstring(r.string.twain_index_key), mcurposition); this.startactivity(intent); } } }

this activity_main1view.xml in lay out folder

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.example.hw_07_final_.titlelistfragment" android:id="@+id/twain_title_list" android:layout_width="match_parent" android:layout_height="match_parent" /> </linearlayout>

this 1 in layout-land

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.example.hw_07_final_.titlelistfragment" android:id="@+id/list" android:layout_weight="1" android:layout_width="0dp" android:layout_height="match_parent" android:background="#00550033"/> <framelayout android:id="@+id/twain_text" android:layout_weight="4" android:layout_width="0dp" android:layout_height="match_parent" /> </linearlayout>

this log cat

you cannot have numbers or uppercase letters when naming xml files.

activity_main1view.xml should activity_mainview.xml excluding "1" layout name.

android xml android-fragments

No comments:

Post a Comment