简体   繁体   English

将数据从活动传递到片段的问题

[英]Issue to pass data from activity to fragment

I have a problem when i pass arraylist from activity to fragment...i need to see only listivew with checkbox selected (taking id from arraylist) while i see list view before take id and list view after taken id from arraylist... 当我将数组列表从活动传递到片段时,我遇到了一个问题...我只需要查看带有选中复选框的listivew(从数组列表获取ID),而我在获取ID之前看到列表视图,而从数组列表获取ID之后看到列表视图...

I show my problem with pics and with code. 我用图片和代码展示我的问题。

with pic: 与图片:

before pass data 传递前数据

enter image description here 在此处输入图片说明

after pass data enter image description here 传递数据后, 在此处输入图像描述

with code: 使用代码:

Bundle bundle = new Bundle();
        bundle.putIntegerArrayList("oki", hm);

        MyListFragment fragment = new MyListFragment();
        fragment.setArguments(bundle);


        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        transaction.replace(R.id.container, fragment);

        transaction.commit();

bundle code to get data: 捆绑代码以获取数据:

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

         bundle = getArguments();
        if (bundle != null) {

            strtext=bundle.getIntegerArrayList("oki");
            System.out.println("PARAM:"+strtext);
        }
}

Who can help me? 谁能帮我? thanks everybody! 谢谢大家!

please refer this 请参考这个

Bundle bundle = new Bundle();
bundle.putStringArrayList("valuesArray", namesArray);
namesFragment myFragment = new namesFragment();
myFragment.setArguments(bundle);

and in Fragment onCreateView method: 并在Fragment onCreateView方法中:

  @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    String strtext = getArguments().getStringArryList("valuesArray");    
    return inflater.inflate(R.layout.fragment, container, false);
}

It is not issue of the passing data between activity to fragment. 不是在活动到片段之间传递数据的问题。 Issue is that Fragment is overlapped on another fragment. 问题是片段重叠在另一个片段上。

Set background color white to parent root of the fragment(each fragment so in future this type of issue never occurs). 将背景色设置为片段的父根(每个片段,因此以后永远不会出现这种类型的问题)。

This will resolved your issue. 这样可以解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM