当我将数据从activity
传递到fragment
时,我得到了这个:
https://i.stack.imgur.com/L0Si4.png
为什么片段重叠?我只需要选中复选框的片段。
这是我传递数据时的代码:
Bundle bundle = new Bundle();
bundle.putIntegerArrayList("oki", hm);
bundle.putIntegerArrayList("okiquantitapizze", hm_quantitàpizze);
System.out.println("PERO:" + bundle);
MyListFragment2 myFragment = MyListFragment2.newInstance(hm,hm_quantitàpizze);
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(android.R.id.content, myFragment);
transaction.commit();
MYLISTFRAGMENT2:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
System.out.println("BUNDLES1 prima:" + bundle);
bundle=getArguments();
System.out.println("BUNDLES1 dopo:" + bundle);
if (bundle != null) {
strtext2 = bundle.getIntegerArrayList("daje");
System.out.println("BUNDLES1 prima:" + strtext2);
quantitàpizze2 = bundle.getIntegerArrayList("daje2");
System.out.println("BUNDLES1 prima:" + quantitàpizze2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the custom_spinner_items for this fragment
//super.onDestroy();
SharedPreferences settings = getContext().getSharedPreferences("states", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = settings.edit();
editor.clear();
editor.commit();
ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_list_2_2, container, false);
return rootView;
}
public static MyListFragment2 newInstance(ArrayList<Integer> hm, ArrayList<Integer> hm_quantitàpizze) {
MyListFragment2 fragment = new MyListFragment2();
Bundle args = new Bundle();
args.putIntegerArrayList("daje", hm);
args.putIntegerArrayList("daje2", hm_quantitàpizze);
fragment.setArguments(args);
return fragment;
}
FRAGMENT_LIST_2_2:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/acab"
android:layout_marginLeft="5dp"
>
<!--android:background="@color/white"-->
<ListView
android:id="@+id/listvieww"
android:layout_marginTop="120dp"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
</FrameLayout>
LISTVIEW的项目:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/container">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimaryDark"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/welcome"
android:textSize="20dp"
android:layout_marginLeft="5dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:layout_marginLeft="5dp"
android:id="@+id/numero_tavolo"
/>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="@color/lbl_name"
android:textSize="24dp"
android:layout_marginLeft="5dp"
/>
<!-- <Button
android:id="@+id/btnLogout"
android:layout_width="122dp"
android:layout_height="wrap_content"
android:layout_marginRight="40dip"
android:background="@color/btn_login"
android:text="@string/btn_logout"
android:textAllCaps="false"
android:textColor="@color/white"
android:textSize="15dp"
android:layout_marginLeft="5dp"
android:onClick="logoutUser"
/>-->
</LinearLayout>
</android.support.v7.widget.Toolbar>
<android.support.design.widget.TabLayout
android:id="@+id/tabss"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMode="scrollable"
android:background="@color/colorPrimaryDark" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpagerr"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" >
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/pero"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>-->
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
如果我PUT
机器人:背景=&#34; @色/白色&#34;成:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/acab"
android:layout_marginLeft="5dp"
android:background="@color/white"
>
<ListView
android:id="@+id/listvieww"
android:layout_marginTop="120dp"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
</FrameLayout>
我明白了:
答案 0 :(得分:0)
你应该在片段背景中使用一些颜色
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/acab"
android:layout_marginLeft="5dp"
android:background="@color/white">
<ListView
android:id="@+id/listvieww"
android:layout_marginTop="120dp"
android:layout_width="fill_parent"
android:layout_height="match_parent">
</ListView>
</FrameLayout>
我可以在这张图片中看到它没有重叠。