有没有办法将布局从一个片段调用到另一个片段?

时间:2016-09-16 04:45:27

标签: android

我的部分应用要求我能够将LinearLayout从一个片段转移到另一个片段。

现在这就是我在MainActivity

中的内容
public ArrayList<LinearLayout> content = new ArrayList<>();
public void addContent(LinearLayout ll)
    {
        content.add(ll);
    }
    public void removeContent(LinearLayout ll)
    {
        content.remove(ll);
    }
    public ArrayList getList()
    {
        return content;
    }

这是我在包含LinearLayout

的片段中的内容
final LinearLayout llWhatBonding = (LinearLayout) view.findViewById(R.id.llWhatBonding);
        CheckBox checkBox1 = (CheckBox)view.findViewById(R.id.checkBox1);
        TextView tvWhatBonding = (TextView)view.findViewById(R.id.tvWhatBonding);
        final ScrollView svWhatBonding = (ScrollView)view.findViewById(R.id.svWhatBonding) ;
        tvWhatBonding.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                svWhatBonding.setVisibility((svWhatBonding.getVisibility() == View.VISIBLE) ? View.GONE : View.VISIBLE);
            }
        });
        checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(content.contains(llWhatBonding)){
                    object.removeContent(llWhatBonding);
                }
                else{
                    object.addContent(llWhatBonding);
                }
            }
        });

这就是我想要将LinearLayout移动到片段中的内容。

    MainActivity object;
    ListView l;
    ArrayAdapter<LinearLayout> adapter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
    {
        View view = inflater.inflate(R.layout.start_screen_layout, container, false);
        object = (MainActivity)getActivity();
        TextView tvtest = (TextView)view.findViewById(R.id.tvtest);
        tvtest.setText(""+object.getList().size());
        l = (ListView)view.findViewById(R.id.listView);
        if(l != null)
        {
            adapter = new ArrayAdapter<LinearLayout>(getActivity(), android.R.layout.simple_list_item_1, object.getList());
            l.setAdapter(adapter);
        }
        return view;
    }

我正在使用ListView来显示每个LinearLayout

现在这就是出现的内容

Right now this is what is showing up

提前致谢。

0 个答案:

没有答案