csh_34 2013-09-28 09:20 采纳率: 0%
浏览 6847
已采纳

Fragment UI不能显示的问题

Activity Layout : activity_text_entry.xml

<?xml version="1.0" encoding="utf-8" ?>
<FrameLayout
           xmlns:android="http://schemas.android.com/apk/res/android"
           android:layout_height="match_parent"
           android:layout_width="match_parent"
           android:id="@+id/fragmentContainer_TextEntry"
           />

Fragment Layout : fragment_text_entry.xml

<?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"
     >

<EditText
     android:id="@+id/Text_Entry_Date"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="@string/choose_date_text"
     android:layout_marginLeft="16dp"
     android:layout_marginRight="16dp"

     />
 <requestFocus />

<EditText
     android:id="@+id/Text_Entry_Title"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:hint="@string/choose_title_text"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp" >


     </EditText>

<EditText
    android:id="@+id/Text_Entry_Content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    android:layout_marginLeft="16dp"
    android:layout_marginRight="16dp"
    android:layout_marginTop="16dp"
    android:ems="100"
    android:gravity="left|top"
    android:hint="@string/enter_text_here"
    android:inputType="textMultiLine" >


</EditText>

<LinearLayout 
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:orientation="horizontal"
    android:gravity="center|bottom"
    >

    <Button
        android:id="@+id/Text_Entry_Button_Save"
        android:text="@string/action_Save"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp" />

    <Button
        android:id="@+id/Text_Entry_Button_Cancel"
        android:text="@string/action_Cancel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp" />

</LinearLayout>

</LinearLayout>

Activity : TextEntryActivity

package com.app.journal_v001;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.widget.Toast;

public class TextEntryActivity extends FragmentActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_text_entry);


        FragmentManager m_fm_text_entry_activity = getSupportFragmentManager();

        Fragment m_f_text_entry_activity = m_fm_text_entry_activity.findFragmentById(R.id.fragmentContainer_TextEntry);

        if(m_f_text_entry_activity == null)
        {

            m_f_text_entry_activity = new Fragment();

            m_fm_text_entry_activity.beginTransaction()
                                    .add(R.id.fragmentContainer_TextEntry, m_f_text_entry_activity)
                                    .commit();
        }
    }
}

我想从 TextEntryActivity(activity) 中呈现 TextEntryFragment(fragment)。 我在不同的地方都保存了一系列的 toasts 来跟踪。我看代码执行到 FragmentManager 的FragmentTransaction,但是然后没有调用 Fragment 的 onCreate/onCreateView。
哪里出错呢?为什么 fragment UI 不显示?

  • 写回答

1条回答 默认 最新

  • JaveZh 2013-10-09 02:17
    关注

    你并没有把fragment加入到activity_text_entry.xml的framelayout里
    形如:

     <fragment class="com.xxx.xxFragment" android:id="@+id/id" android:layout_weight="1"
            android:layout_width="0px" android:layout_height="match_parent"
            />
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 spring后端vue前端
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题