android - Fragment not showing in activity -


i have fragment own layout, , activity in fragment should added has layout:

<?xml version="1.0" encoding="utf-8"?>    <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"     android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin"     android:paddingright="@dimen/activity_horizontal_margin"     android:paddingtop="@dimen/activity_vertical_margin"     android:paddingbottom="@dimen/activity_vertical_margin">      <fragment     android:name="com.myapp.myfragment"     android:id="@+id/myfragment"     android:layout_weight="1"     android:layout_width="0dp"     android:layout_height="match_parent"     tools:layout="@layout/myfragment_layout" /> </relativelayout> 

then in activity class:

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_info);      fragmentmanager fm = getfragmentmanager();      fragment = fm.findfragmentbyid(r.id.myfragment);     if (fragment == null) {         fragment = new myfragment();          fragmenttransaction ft = fm.begintransaction();         ft.add(r.id.myfragment, fragment, "myfragment");         ft.commit();     } } 

the oncreateview of fragment is:

@override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {     super.oncreateview(inflater, container, savedinstancestate);      return inflater.inflate(r.layout.myfragment, container, false); } 

but fragment not showing. no exception thrown. activity remains blank.

what missing?

replace below lines

android:layout_weight="1" android:layout_width="0dp"

with

android:layout_width="match_parent" or android:layout_width="wrap_content"

because relativelayout doesn't accept layout_weight.


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -