【问题标题】:listfragment inside a fragment how to get list片段内的listfragment如何获取列表
【发布时间】:2014-05-19 16:07:32
【问题描述】:

我在片段中有一个列表片段。我想在 onActivityCreated 中获取父片段内的列表,但我不知道该怎么做。 我想这样做是因为列表是一个自定义列表视图,带有 2 个文本视图和一个复选框,我需要查看哪些项目被选中。

我的父片段:

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

    getChildFragmentManager()
    .beginTransaction()
    .replace(R.id.list_topgain_frame, new ListFragmentTopGain())
    .commit();

    return inflater.inflate(R.layout.parier3, container, false);
}

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    btnGainValider = (Button) getActivity().findViewById(R.id.btnGainValider);
    btnGainValider.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

        }
    });
}

我用 ListFragment 替换的框架布局:

<FrameLayout
            android:id="@+id/list_choixamis_frame"
            android:layout_width="match_parent"
            android:layout_height="150dp"
            android:layout_below="@id/txvChoixAmis"
            android:layout_marginBottom="20dp" />

【问题讨论】:

    标签: android android-fragments android-listview android-listfragment android-nested-fragment


    【解决方案1】:

    我发现了一个小技巧,因为我仍然找不到如何在父片段中获取列表..

    无论如何,如果其他人遇到此问题,我会通过在我的 customAdapter 中使用侦听器绕过。然后我传递信息:customAdapter -> ListFragment -> ParentFragment。

    【讨论】:

      猜你喜欢
      • 2015-01-03
      • 1970-01-01
      • 2020-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多