this is the screenshot of overwritten screen of both fragments我已經搜查的網站上,但我無法找到解決辦法,這裏是我的代碼:片段沒有發現的ID在android中的視圖ID更改時,它顯示兩個屏幕上覆蓋?
public class MyLawyerFragment extends Fragment {
ImageButton im1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v1 = inflater.inflate(R.layout.activity_mylawyer,
container, false);
im1 = (ImageButton) v1.findViewById(R.id.imageButton);
im1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Fragment fragment = new tasks();
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.replace(R.id.drawer_layout, fragment);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
}
});
return v1;
}
}
這裏是我的下一個片段的代碼,而我想去從最後一個:
public class tasks extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
{
super.onCreateView(inflater, container, savedInstanceState);
final View rootview = inflater.inflate(R.layout.activity_addlawyer, container, false);
return rootview;
}}}
這裏是任務片段的XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:id="@+id/rel3"
android:layout_marginTop="60dp"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ADD LAWYER"
android:id="@+id/textView29"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#a8a8a8"
android:layout_below="@+id/textView29"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_marginLeft="18dp"
android:layout_marginTop="58dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Email ID :"
android:id="@+id/textView30"
android:layout_marginStart="31dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_marginTop="8dp"
android:layout_marginRight="18dp"
android:background="@drawable/rounded_border_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText31"
android:layout_below="@+id/textView30"
android:layout_alignLeft="@+id/textView30"
android:layout_alignStart="@+id/textView30" />
<Button
android:layout_marginLeft="15dp"
android:background="@drawable/mybuttonred"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:text="CANCEL"
android:textColor="#ffffff"
android:id="@+id/button6"
android:layout_gravity="right"
android:layout_alignTop="@+id/button5"
android:layout_alignRight="@+id/editText32"
android:layout_alignEnd="@+id/editText32"
android:layout_toEndOf="@+id/button5"
android:layout_toRightOf="@+id/button5" />
<Button
android:layout_marginLeft="18dp"
android:background="@drawable/mybuttongreen"
android:layout_width="160dp"
android:layout_height="wrap_content"
android:text="SAVE LAWYER DETAILS"
android:textColor="#ffffff"
android:id="@+id/button5"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_marginTop="29dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Phone Number :"
android:id="@+id/textView31"
android:layout_below="@+id/editText31"
android:layout_alignLeft="@+id/editText31"
android:layout_alignStart="@+id/editText31" />
<EditText
android:layout_marginTop="8dp"
android:layout_marginRight="18dp"
android:background="@drawable/rounded_border_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:ems="10"
android:id="@+id/editText32"
android:layout_below="@+id/textView31"
android:layout_alignLeft="@+id/textView31"
android:layout_alignStart="@+id/textView31" />
現在我有這個錯誤的logcat:
Process: com.orion.android.mylawyerdiary, PID: 5453
java.lang.IllegalArgumentException: No view found for id 0x7f0d006c (com.orion.android.mylawyerdiary:id/rel3) for fragment tasks{22ba0560 #1 id=0x7f0d006c}
而且我無法解決它...請人幫助我。
這是所有片段連接我的導航抽屜活動的xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:openDrawer="start"
>
<include
layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.NavigationView
android:theme="@style/NavigationDrawerStyle"
android:background="#2B292A"
app:itemTextColor="#ffffff"
app:itemIconTint="#C09E57"
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/activity_navdrawer_header"
app:menu="@menu/menu_navdrawer" />
</android.support.v4.widget.DrawerLayout>
清理您的項目並重建它 –
'rel3' id是否出現在'activity_mylawyer' .xml中? –
@R.Zagórski不,rel3 id只存在於addlawyer.xml – Annie