我的部分应用要求我能够将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
。
现在这就是出现的内容
提前致谢。