标签: android-nested-fragment

对话框中的Android Maps API v2

我试图在对话框中显示GMaps,可以这样做吗?

我有布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/LoginFormContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="0dp" >

<fragment
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/mapView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    class="com.google.android.gms.maps.MapFragment"
    android:gravity="center" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

并将此XML扩展为对话框,如下所示......

    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.dialog_location, null);

    AlertDialog.Builder builder = new AlertDialog.Builder(context).setView(layout);
    AlertDialog alertDialog = builder.create();
    alertDialog.show();
Run Code Online (Sandbox Code Playgroud)

但是,在通货膨胀期间,我得到运行时错误......

02-02 12:52:56.045: W/dalvikvm(23044): threadid=1: thread exiting with uncaught exception (group=0x40f862a0)
02-02 12:52:56.050: E/AndroidRuntime(23044): FATAL EXCEPTION: main
02-02 12:52:56.050: E/AndroidRuntime(23044): android.view.InflateException: Binary XML file line #8: Error inflating class fragment
02-02 12:52:56.050: E/AndroidRuntime(23044):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-02 12:52:56.050: E/AndroidRuntime(23044): …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-maps-v2 android-nested-fragment

5
推荐指数
1
解决办法
5814
查看次数

将片段添加到片段(嵌套片段)中

我想将youtube片段动态添加到我现有的片段中。我使用的代码如下:

        // setting the Youtube Player Dynamically
private int setYoutubePlayer(String desc, View view, int prevID,
        Bundle input) {

    if (desc.indexOf("=") != -1) {
        desc = desc.substring(desc.indexOf("=") + "=".length());
    } else {
        return prevID;
    }

    final String url = desc;

    LinearLayout videoLayout = new LinearLayout(view.getContext());
    videoLayout.setOrientation(LinearLayout.VERTICAL);
    prevID++;
    videoLayout.setId(prevID);

    FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager
            .beginTransaction();

    fragment.setVideoId(url);
    LinearLayout itemLayout = (LinearLayout) view.findViewById(R.id.items);
    itemLayout.addView(videoLayout);

    fragmentTransaction.add(itemLayout.getId(), fragment,
            "youtube fargment " + prevID);

    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();

    return prevID;
}
Run Code Online (Sandbox Code Playgroud)

我需要将YouTube片段放入适当的片段中。当我检查何时总是加载新片段时(在片段之间滑动时),新的内部片段需要是第一个加载的片段。

任何帮助都会很高兴地被接受。

求助:谢谢科比,你是对的。我不得不替换“ getActivity()。getSupportFragmentManager();” 与“ …

android youtube-api android-fragments android-viewpager android-nested-fragment

5
推荐指数
1
解决办法
1933
查看次数

没有找到id的视图 - DialogFragment + Fragment

我有一个简单布局的DialogFragment.我想添加一个片段(并在将来将此片段替换为另一个片段)到DialogFragment布局内的FrameLayout.但是,添加新片段的方法失败,并显示错误:

片段Fragment_AlertsManage {41e7cb68}"找不到id 0x7f0b004f com.kennel39.diabeteslive_adtdev:id/frameAlertsContainer的视图"

我检查了我的xml,尝试了不同的方法,并在stackoverflow上读了一些类似的问题,但我找不到解决方案.

public class DialogManageAlerts extends DialogFragment{
static int patient_id;

public static DialogManageAlerts newInstance(int given_patient_id){
    DialogManageAlerts frag = new DialogManageAlerts();
    patient_id = given_patient_id;

    Bundle bund = new Bundle();
    bund.putInt("Patient_id", patient_id);
    frag.setArguments(bund);
    return frag;
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View mainView = inflater.inflate(R.layout.dialog_alerts_master, container, false);              
    getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);

    FragmentManager myFragmentManager = getFragmentManager();
    FragmentTransaction myTransact = myFragmentManager.beginTransaction();
    Fragment_AlertsManage manageAlertsFragment = new Fragment_AlertsManage();
    myTransact.add(R.id.frameAlertsContainer, manageAlertsFragment);
    myTransact.commit();

    return mainView;
}
Run Code Online (Sandbox Code Playgroud)

layout.dialog_alerts_master:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-dialogfragment fragmenttransaction android-nested-fragment

3
推荐指数
1
解决办法
2208
查看次数

在调用子片段时找不到 id 的视图

所以,我有MAIN ACTIVITY(M)两个FRAGMENTS(F1, F2)和一个BUTTON(B)F1

现在,当主要活动开始时F1会自动加载,这很好,我想要做的是F2在我点击Bwhich is on 时开始F1

以下是我的 Fragment1 代码,即 HomeFragment:

package info.androidhive.slidingmenu;

import java.lang.reflect.Field;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;

public class HomeFragment extends Fragment {

 public static HomeFragment newInstance() 
 {
        return new HomeFragment();
    }

public HomeFragment(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState){


    View rootView = …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-nested-fragment

3
推荐指数
1
解决办法
2354
查看次数

带有嵌套/子片段的Android Backstack

我对嵌套片段的堆栈方式有一个问题,并且非常感谢所提供的任何帮助.

我有片段A和片段B.片段A包含另一个片段(ButtonFragment).在活动的onCreate中,我加载片段A,而不是切换到片段B.当我回到片段A(从后台堆栈中)时,我得到以下错误.

异常调度完成信号.

E/MessageQueue-JNI(6330):MessageQueue回调中的异常:handleReceiveCallback

E/MessageQueue-JNI(6330):android.view.InflateException:二进制XML文件行#16:错误膨胀类片段

...

引起:java.lang.IllegalArgumentException:二进制XML文件行16:重复id 0x7f080000,标记null或父id 0x0与另一个片段com.example.fragmentnavigation.MainActivity $ ButtonFragment

没有子片段导航工作.也许我必须添加一些ChildFragmentManager处理,但我不知道在哪里和哪里.我希望你能帮助我.

MainLayout

<LinearLayout 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:orientation="vertical" >

<Button
    android:id="@+id/button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/app_name" />

<FrameLayout 
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.example.fragmentnavigation.MainActivity"
    tools:ignore="MergeRootFrame" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

片段布局

<LinearLayout 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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.fragmentnavigation.MainActivity$FragmentA" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <fragment 
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:name="com.example.fragmentnavigation.MainActivity$ButtonFragment"/> 

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

MainAcitivity

public class MainActivity extends FragmentActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction()
                .add(R.id.container, new …
Run Code Online (Sandbox Code Playgroud)

navigation android android-fragments android-nested-fragment fragment-backstack

3
推荐指数
1
解决办法
711
查看次数

二进制XML文件第26行:重复的ID,标签为空或父ID为另一个片段

我正在尝试将一个片段插入另一个片段,并且我已经成功做到这一点,直到我第一次吃完主要片段为止,但是当我尝试重新加载片段时,应用崩溃了,我有这个错误:

Caused by: java.lang.IllegalArgumentException: Binary XML file line #26:
Duplicate id 0x7f0e00e2, tag null, or parent id 0xffffffff with another
fragment for com.google.android.gms.location.places.ui.PlaceAutocompleteFragment
Run Code Online (Sandbox Code Playgroud)

这是我的片段

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View  rootView = inflater.inflate(R.layout.source_destination,container, false);
PlaceAutocompleteFragment sourcr_autocompleteFragment = (PlaceAutocompleteFragment)
          getActivity().getFragmentManager()
.findFragmentById(R.id.sourcr_autocomplete_fragment);
return rootView;

// List item

}
Run Code Online (Sandbox Code Playgroud)

这是我的XML

 <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
        android:padding="10dp"
        android:background="@color/colorPrimary"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
       <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_medium"
            android:layout_marginBottom="@dimen/margin_medium">

            <fragment
                android:id="@+id/sourcr_autocomplete_fragment"    
                android:name="com.google.android.gms.location.places.ui.PlaceAutocompleteFragment"           
              android:layout_width="match_parent"
              android:layout_height="wrap_content" />

        </android.support.v7.widget.CardView>
    </LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-nested-fragment

3
推荐指数
2
解决办法
3429
查看次数

Tab中的ViewPager无法正确显示项目

我有一个FragmentActivity来设置tabhost.每个选项卡都是一个名为TabFragment的简单片段.TabFragment有一个ViewPager,在这种情况下它是antonyt的InfiniteViewPager (在这里讨论:ViewPager作为循环队列/包装).

(主要)问题如下:

  1. 我启动了应用程序.我点击第二个标签.当我看到与第一个标签中相同的内容时,只有一个空白屏幕.向右滚动几次后,我看到了我的TextViews.

  2. 在ViewPagers中滚动片段并更改选项卡最终会导致停止和FC,并且不会抛出任何明确的异常.

这是我对Fragments的第一次采取,我必须承认,我不理解观察到的行为.

任何提示将不胜感激.

整个项目都在这里.

代码:

使用TabHost的FragmentActivity:



    package com.example.viewpagerintab;

    import java.util.HashMap;

    import android.content.Context;
    import android.os.Bundle;
    import android.support.v4.app.Fragment;
    import android.support.v4.app.FragmentActivity;
    import android.support.v4.app.FragmentTransaction;
    import android.view.View;
    import android.widget.TabHost;
    import android.widget.TabHost.TabContentFactory;

    public class TabsFragmentActivity extends FragmentActivity implements
            TabHost.OnTabChangeListener {

        private TabHost mTabHost;
        private HashMap mapTabInfo = new HashMap();
        private TabInfo mLastTab = null;

        public TabsFragmentActivity() {

        }

        private class TabInfo {
            private String tag;
            private Class clss;
            private Bundle args;
            private Fragment fragment;

            TabInfo(String tag, …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-viewpager android-tabs android-nested-fragment

2
推荐指数
1
解决办法
2505
查看次数

android.support.v4.app.Fragment:undefined方法getChildFragmentManager()

我正在使用ActionBarSherlockViewPageIndicator我试图实现嵌套片段,但getChildFragmentManager()我的方法未定义android.support.v4.app.Fragments.

没有其他错误,ABS和VPI按预期工作.

我没有使用支持库v13,我使用的是最新版本,我已经清理了我的项目.正常人android.app.Fragment不会抱怨getChildFragmentManager().

我还尝试重新安排支持库依赖项(ABS中的android-support-v4.jar,引用它的VPI和主项目,或者作为外部jar的android-support-v4.jar),但getChildFragmentManager()仍未定义.

如果我删除VPI getChildFragmentManager(),但工作,但VPI当然停止工作.所以,依赖项肯定存在问题,但我的想法已经用完了.

任何帮助将非常感激!

android android-fragments android-support-library android-nested-fragment

2
推荐指数
1
解决办法
1万
查看次数

按下手机的后退按钮后,ViewPager 不会生成 UI

这是我的代码:

主页.java

import android.os.Bundle;
import android.app.ActionBar;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Home extends Fragment {

    private TextView textView23;
    private ImageView addNewSalesInquery;
    private LinearLayout addNewSalesButton;
    private View view;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
        super.onCreate(savedInstanceState);

        view = inflater.inflate(R.layout.activity_home,container,false);

        //Intializing instance variables
        //addNewSalesInquery = (ImageView)findViewById(R.id.add_new_sales_inq);
        //textView23 = (TextView)findViewById(R.id.textView23);
        //textView23.setSelected(true);
         addNewSalesButton = (LinearLayout)view.findViewById(R.id.add_new_sales_btn); …
Run Code Online (Sandbox Code Playgroud)

java android android-fragments android-viewpager android-nested-fragment

2
推荐指数
1
解决办法
752
查看次数

从BackStack返回后,ListFragment加载空列表

这是我在同一件事上的第二篇文章,我还在等人指导我.我面临的问题可能非常简单,简而言之,我有这个ListFragment填充列表调用webservice,这很好.当用户选择任何项目时,我替换另一个片段并将其添加到BackStack

问题从这里开始,它弹出ListFragment但它总是空的或空白.但我已经以各种可能的方式检查了日志,发现数据存在,出于某种原因,列表保持空白.请帮帮我一个人......

在我使用的MainActivity中DrawerItemCustomAdapter,这就是我替换片段的方式

private void selectItem(int position) {

    android.support.v4.app.Fragment fragment = null;

    switch (position) {
    case 0:
    {
        fragment = new EventFragment();
    }
        break;
    case 1:
        fragment = new ScheduleFragment();
        break;
    case 2:
        fragment = new NewsFragment();
        break;
    case 3:
        fragment = new TeamFragment();
        break;
    case 4:
        fragment = new VenueFragment();
        break;
    case 5:
        fragment = new NewsFragment();
        break;

    default:
        break;
    }

    if (fragment != null) {
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit(); …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-listfragment back-stack android-nested-fragment

2
推荐指数
1
解决办法
2181
查看次数