
这是我的代码.
activity_pontix(陆地和肖像模式)
<linearLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:background="#CCFF99" androID:orIEntation="vertical" > <TextVIEw androID:ID="@+ID/Pontix" androID:layout_wIDth="match_parent" androID:layout_height="50dp" androID:gravity="center_horizontal" androID:text="@string/pontix" androID:background="#ffffff" androID:textcolor="#000000" androID:textSize="40dp" /> <linearLayout androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:orIEntation="horizontal" > <fragment androID:ID="@+ID/sIDeMenu" androID:name="com.example.pontix.SIDeMenu" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="3" /> <fragment androID:ID="@+ID/content" androID:name="com.example.pontix.ContentPrevIEw" androID:layout_wIDth="0dp" androID:layout_height="match_parent" androID:layout_weight="1" /> </linearLayout></linearLayout>
SIDeMenu.java
public class SIDeMenu extends ListFragment{ OnMenuSelectedListener setSelected; public interface OnMenuSelectedListener { public voID onItemSelected(int position); } @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); int layout = R.layout.sIDe_menu_item; setlistadapter(new ArrayAdapter<String>(getActivity(),layout,MenuItem.Items)); } @OverrIDe public voID onStart() { super.onStart(); if (getFragmentManager().findFragmentByID(R.ID.sIDeMenu) != null) { getListVIEw().setChoiceMode(ListVIEw.CHOICE_MODE_SINGLE); } } @OverrIDe public voID onAttach(Activity activity) { super.onAttach(activity); try { setSelected = (OnMenuSelectedListener) activity; } catch (ClassCastException e) { throw new ClassCastException(activity.toString() + " must implement OnMenuSelectedListener"); } } @OverrIDe public voID onListItemClick(ListVIEw l,VIEw v,int position,long ID) { setSelected.onItemSelected(position); // Set the item as checked to be highlighted when in two-pane layout getListVIEw().setItemChecked(position,true); }} ContentPrevIEw.java
public class ContentPrevIEw extends Fragment{ final static String ARG_position = "position"; int mCurrentposition = -1; @OverrIDe public VIEw onCreateVIEw(LayoutInflater inflater,VIEwGroup container,Bundle savedInstanceState) { if (savedInstanceState != null) { mCurrentposition = savedInstanceState.getInt(ARG_position); } return inflater.inflate(R.layout.content_vIEw,container,false); } @OverrIDe public voID onStart() { super.onStart(); Bundle args = getArguments(); if (args != null) { updateContentPrevIEw(args.getInt(ARG_position)); } else if (mCurrentposition != -1) { updateContentPrevIEw(mCurrentposition); } } public voID updateContentPrevIEw(int position) { switch(position) { case 1: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Gincana"); mCurrentposition = position; break; } case 2: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Tarefas"); mCurrentposition = position; break; } case 3: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Ranking"); mCurrentposition = position; break; } case 4: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Amigos"); mCurrentposition = position; break; } case 5: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Perfil"); mCurrentposition = position; break; } case 6: { TextVIEw article = (TextVIEw) getActivity().findVIEwByID(R.ID.contentVIEw); article.setText("Voce estava na aba Sobre"); mCurrentposition = position; break; } } } @OverrIDe public voID onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt(ARG_position,mCurrentposition); }} PontixActivity.java
public class PontixActivity extends FragmentActivity implements SIDeMenu.OnMenuSelectedListener { @OverrIDe public voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.activity_pontix); Intent intent = getIntent(); int code = intent.getIntExtra(GincanaActivity.EXTRA_CONTENT,0); SIDeMenu sIDeMenu = new SIDeMenu(); sIDeMenu.setArguments(getIntent().getExtras()); getSupportFragmentManager().beginTransaction().add(R.ID.sIDeMenu,sIDeMenu).commit(); ContentPrevIEw contentFragment = (ContentPrevIEw) getSupportFragmentManager().findFragmentByID(R.ID.content); if (contentFragment != null) { contentFragment.updateContentPrevIEw(code); } } public voID onItemSelected(int position) { switch(position) { case 0: { Intent contentVIEw = new Intent(this,GincanaActivity.class); startActivity(contentVIEw); break; } case 1: { Intent contentVIEw = new Intent(this,TarefaActivity.class); startActivity(contentVIEw); break; } case 2: { Intent contentVIEw = new Intent(this,RankingActivity.class); startActivity(contentVIEw); break; } case 3: { Intent contentVIEw = new Intent(this,MainActivity.class); startActivity(contentVIEw); break; } case 4: { Intent contentVIEw = new Intent(this,MainActivity.class); startActivity(contentVIEw); break; } case 5: { Intent contentVIEw = new Intent(this,MainActivity.class); startActivity(contentVIEw); break; } } }} 这是错误日志.
08-03 13:13:58.745: W/IinputConnectionWrapper(13847): showStatusIcon on inactive inputConnection08-03 13:14:09.065: D/AbsListVIEw(13847): Get MotionRecognitionManager08-03 13:14:09.065: D/AbsListVIEw(13847): Get MotionRecognitionManager08-03 13:14:12.310: D/AndroIDRuntime(13847): Shutting down VM08-03 13:14:12.310: W/dalvikvm(13847): threadID=1: thread exiting with uncaught exception (group=0x40c661f8)08-03 13:14:12.340: E/AndroIDRuntime(13847): FATAL EXCEPTION: main08-03 13:14:12.340: E/AndroIDRuntime(13847): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.pontix/com.example.pontix.PontixActivity}: androID.vIEw.InflateException: Binary XML file line #21: Error inflating class fragment08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1970)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1995)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.handle@R_675_4404@Activity(ActivityThread.java:3365)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.access0(ActivityThread.java:128)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:1165)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.os.Handler.dispatchMessage(Handler.java:99)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.os.Looper.loop(Looper.java:137)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.main(ActivityThread.java:4514)08-03 13:14:12.340: E/AndroIDRuntime(13847): at java.lang.reflect.Method.invokeNative(Native Method)08-03 13:14:12.340: E/AndroIDRuntime(13847): at java.lang.reflect.Method.invoke(Method.java:511)08-03 13:14:12.340: E/AndroIDRuntime(13847): at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:993)08-03 13:14:12.340: E/AndroIDRuntime(13847): at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:760)08-03 13:14:12.340: E/AndroIDRuntime(13847): at dalvik.system.NativeStart.main(Native Method)08-03 13:14:12.340: E/AndroIDRuntime(13847): Caused by: androID.vIEw.InflateException: Binary XML file line #21: Error inflating class fragment08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:697)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:739)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.rInflate(LayoutInflater.java:742)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:489)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:396)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.inflate(LayoutInflater.java:352)08-03 13:14:12.340: E/AndroIDRuntime(13847): at com.androID.internal.policy.impl.PhoneWindow.setContentVIEw(PhoneWindow.java:280)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.Activity.setContentVIEw(Activity.java:1892)08-03 13:14:12.340: E/AndroIDRuntime(13847): at com.example.pontix.PontixActivity.onCreate(PontixActivity.java:13)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.Activity.performCreate(Activity.java:4562)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1053)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1934)08-03 13:14:12.340: E/AndroIDRuntime(13847): ... 12 more08-03 13:14:12.340: E/AndroIDRuntime(13847): Caused by: java.lang.IllegalStateException: Fragment com.example.pontix.SIDeMenu dID not create a vIEw.08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.support.v4.app.FragmentActivity.onCreateVIEw(FragmentActivity.java:295)08-03 13:14:12.340: E/AndroIDRuntime(13847): at androID.vIEw.LayoutInflater.createVIEwFromTag(LayoutInflater.java:669)08-03 13:14:12.340: E/AndroIDRuntime(13847): ... 23 more08-03 13:14:12.355: D/dalvikvm(13847): GC_CONCURRENT freed 152K,3% free 13194K/13575K,paused 1ms+3ms08-03 13:14:12.355: D/AbsListVIEw(13847): [unregisterDoubleTapMotionListener]08-03 13:14:12.355: I/MotionRecognitionManager(13847): .unregisterListener : / Listener count = 0->0,Listener=androID.Widget.AbsListVIEw@419278a808-03 13:14:12.355: D/AbsListVIEw(13847): [unregisterDoubleTapMotionListener]08-03 13:14:12.355: I/MotionRecognitionManager(13847): .unregisterListener : / Listener count = 0->0,Listener=androID.Widget.AbsListVIEw@4192d5e008-03 13:14:12.360: D/AbsListVIEw(13847): [unregisterDoubleTapMotionListener]08-03 13:14:12.360: I/MotionRecognitionManager(13847): .unregisterListener : / Listener count = 0->0,Listener=androID.Widget.AbsListVIEw@41963500解决方法 你的两个片段都需要公共的空构造函数: public class SIDeMenu extends ListFragment{ public SIDeMenu(){} ...public class ContentPrevIEw extends Fragment{ public ContentPrevIEw(){} ... 总结 以上是内存溢出为你收集整理的android – 更改方向时片段膨胀错误全部内容,希望文章能够帮你解决android – 更改方向时片段膨胀错误所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)