Android 从活动调用片段时,找不到该片段id为0x7f0c0078的视图

Android 从活动调用片段时,找不到该片段id为0x7f0c0078的视图,android,xml,listview,android-fragments,Android,Xml,Listview,Android Fragments,在我的应用程序中,我必须调用活动的片段。所以我用的是Frgament mangaer。当我运行代码时,它抛出上面的异常 这是我的主要活动 public class UserDashBoardActivity extends DrawerActivity { private Context context; private ImageButton searchBtn; private ImageButton favBtn; p

在我的应用程序中,我必须调用活动的片段。所以我用的是Frgament mangaer。当我运行代码时,它抛出上面的异常

这是我的主要活动

  public class UserDashBoardActivity extends DrawerActivity {


        private Context context;
        private ImageButton searchBtn;
        private ImageButton favBtn;
        private ImageButton profileBtn;
        private ImageButton reminderBtn;
        private ImageButton logoutBtn;
        private ImageButton notificationBtn;
        private ImageView seatchIcon;
        private DrawerLayout mDrawerLayout;
        private ListView mDrawerList;
        private ActionBarDrawerToggle mDrawerToggle;
        // slide menu items
        private String[] navMenuTitles;
        private TypedArray navMenuIcons;

        @Override
        protected void onStart() {
            super.onStart();
            AppActivityStatus.setActivityStarted();
            AppActivityStatus.setActivityContext(context);
        }

        @Override
        protected void onPause() {
            super.onPause();
            AppActivityStatus.setActivityStoped();

        }

        @Override
        protected void onResume() {
            super.onResume();
            AppActivityStatus.setActivityStarted();
        }

        @Override
        protected void onStop() {
            super.onStop();
            AppActivityStatus.setActivityStoped();
        }


        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            // Inflate the menu; this adds items to the action bar if it is present.
            getMenuInflater().inflate(R.menu.menu_user_dash_boad, menu);
            return true;
        }

        // delete the selected event from event list added here
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {

            switch (item.getItemId()) {
                case R.id.action_notify:
                    return true;

                case R.id.action_favourite:
                    return true;
                case R.id.action_navigation:

            }

            return super.onOptionsItemSelected(item);
        }


        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.user_dash_board);
            context = getApplicationContext();
            searchBtn = (ImageButton) findViewById(R.id.search_btn);
            favBtn = (ImageButton) findViewById(R.id.fav_btn);
            profileBtn = (ImageButton) findViewById(R.id.profile_btn);
            reminderBtn = (ImageButton) findViewById(R.id.reminder_btn);
            notificationBtn = (ImageButton) findViewById(R.id.notification_btn);
            logoutBtn = (ImageButton) findViewById((R.id.logout_btn));
            final EditText Search = (EditText) findViewById(R.id.emailAddress);
            searchBtn.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    Intent regAct = new Intent(getApplicationContext(), SearchActivity.class);
                    // Clears History of Activity
                    regAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(regAct);
                }
            });

            favBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
//here i am calling the fragment
                    MyFavouritesFragment fragment = new MyFavouritesFragment();


                    if (fragment != null) {
                        android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
                        fragmentManager.beginTransaction()
                                .replace(R.id.container, fragment).commit();
                    }
                }
            });

            profileBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View arg0) {
                    Intent tabAct = new Intent(getApplicationContext(), AboutCollegeFragment.class);
                    tabAct.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(tabAct);

                }
            });

        }
    }
这是我的片段被称为

public class MyFavouritesFragment extends Fragment {
    private FavouriteDelegates favouriteDelegates = new FavouriteDelegates();
    private Gson gson = new Gson();
    private Context context;
    private List<CollegeMO> collegeMOs = new ArrayList<>();

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        final View view = inflater.inflate(R.layout.my_favourites_list_view, container, false);
return view;

    }

    private class FavouriteCollege extends BaseAdapter {
            LayoutInflater mInflater;
            TextView collegeText;


            FavouriteCollege() {
                mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            }

            @Override
            public int getCount() {
                return collegeMOs.size();
            }

            @Override
            public Object getItem(int position) {
                return position;
            }

            @Override
            public long getItemId(int position) {
                return 0;
            }

            // show list values name and mobile number in contact page
            @Override
            public View getView(final int position, View convertView, ViewGroup parent) {

                if (convertView == null)
                    convertView = mInflater.inflate(R.layout.my_favourites, null);
                collegeText = (TextView) convertView.findViewById(R.id.clg_details);
                collegeText.setText(collegeMOs.get(position).getCollegeName());
                return convertView;
            }

        }
    }
公共类MyFavoriteSFragment扩展了片段{
private FavoriteDelegates FavoriteDelegates=新的FavoriteDelegates();
private Gson Gson=new Gson();
私人语境;
private List collegeMOs=new ArrayList();
@凌驾
CreateView上的公共视图(布局、充气机、视图组容器、捆绑包保存状态){
super.onCreate(savedInstanceState);
最终视图=充气机。充气(R.layout.my\u favorites\u list\u视图,容器,false);
返回视图;
}
私人班级优惠学院扩展BaseAdapter{
拉平机;
TextView CollegetText;
收藏学院(){
mInflater=(LayoutInflater)context.getSystemService(context.LAYOUT\u充气机\u服务);
}
@凌驾
public int getCount(){
返回collegeMOs.size();
}
@凌驾
公共对象getItem(int位置){
返回位置;
}
@凌驾
公共长getItemId(int位置){
返回0;
}
//在联系人页面中显示列表值姓名和手机号码
@凌驾
公共视图getView(最终整数位置、视图转换视图、视图组父视图){
if(convertView==null)
convertView=mInflater.flate(R.layout.my_favorites,null);
colleGetText=(TextView)convertView.findViewById(R.id.clg_详细信息);
collegeText.setText(collegeMOs.get(position.getCollegeName());
返回视图;
}
}
}
这是我的主要活动xml

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@color/appblue"
    android:orientation="vertical">



    <ImageButton
        android:id="@+id/search_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="5dp"
        android:layout_marginRight="150dp"
        android:layout_marginTop="70dp"
        android:background="@drawable/search_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/searchCollege"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="80dp"
        android:layout_marginRight="100dp"
        android:layout_marginTop="20dp"
        android:text="@string/search_college"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <ImageButton
        android:id="@+id/fav_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="150dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="-167dp"
        android:background="@drawable/fav_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/myFavourites"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="370dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="-30dp"
        android:text="@string/my_favourites"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <ImageButton
        android:id="@+id/profile_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_marginLeft="90dp"
        android:layout_marginRight="150dp"
        android:layout_marginTop="30dp"
        android:background="@drawable/profile_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/myProfile"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="105dp"
        android:layout_marginRight="100dp"
        android:layout_marginTop="20dp"
        android:text="@string/my_profile"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <ImageButton
        android:id="@+id/notification_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="150dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="-165dp"
        android:background="@drawable/notification_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/notification"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="390dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:text="@string/notification"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <ImageButton
        android:id="@+id/reminder_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="55dp"
        android:layout_marginRight="200dp"
        android:layout_marginTop="20dp"
        android:background="@drawable/reminder_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/reminder"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="100dp"
        android:layout_marginTop="20dp"
        android:text="@string/reminder"
        android:textColor="@color/green"
        android:textSize="20sp" />

    <ImageButton
        android:id="@+id/logout_btn"
        android:layout_width="115dp"
        android:layout_height="120dp"
        android:layout_gravity="center_horizontal"
        android:layout_marginLeft="150dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="-220dp"
        android:background="@drawable/logout_blue"
        android:gravity="center" />

    <TextView
        android:id="@+id/logout"
        android:layout_width="wrap_content"
        android:layout_height="80dp"
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="410dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="20dp"
        android:text="@string/logout"
        android:textColor="@color/green"
        android:textSize="20sp" />
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="1000dp"
        android:layout_height="1000dp"
        android:layout_gravity="center"
        >
    </FrameLayout>
</LinearLayout>

这是片段listview xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <ListView
        android:id="@+id/course_detail_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbarStyle="outsideOverlay" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/appblue">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="40dp"
        android:background="@color/white">
        <TableRow
            android:id="@+id/tableRow1"
            android:layout_height="wrap_content"
            android:layout_width="match_parent">
        <ImageView
            android:id="@+id/clgImage"
            android:src = "@drawable/ic_launcher"
            android:layout_weight="1" android:background="@color/white"
            android:padding="20dip" android:gravity="center"/>
        <TextView
            android:id="@+id/clg_details" android:text="Row 2 column 2"
            android:layout_weight="1" android:background="@color/white"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
            <ImageView
                android:id="@+id/downloadImage"
                android:src = "@drawable/ic_launcher"
                android:layout_weight="1" android:background="@color/white"
                android:padding="20dip" android:gravity="center"/>
        </TableRow>

    </LinearLayout>

    </LinearLayout>

这是我最喜欢的listview xml的项

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <ListView
        android:id="@+id/course_detail_list_view"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbarStyle="outsideOverlay" />

</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/appblue">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:layout_marginBottom="40dp"
        android:layout_marginLeft="40dp"
        android:layout_marginRight="40dp"
        android:layout_marginTop="40dp"
        android:background="@color/white">
        <TableRow
            android:id="@+id/tableRow1"
            android:layout_height="wrap_content"
            android:layout_width="match_parent">
        <ImageView
            android:id="@+id/clgImage"
            android:src = "@drawable/ic_launcher"
            android:layout_weight="1" android:background="@color/white"
            android:padding="20dip" android:gravity="center"/>
        <TextView
            android:id="@+id/clg_details" android:text="Row 2 column 2"
            android:layout_weight="1" android:background="@color/white"
            android:textColor="#000000"
            android:padding="20dip" android:gravity="center"/>
            <ImageView
                android:id="@+id/downloadImage"
                android:src = "@drawable/ic_launcher"
                android:layout_weight="1" android:background="@color/white"
                android:padding="20dip" android:gravity="center"/>
        </TableRow>

    </LinearLayout>

    </LinearLayout>

在主活动xml中没有容器(
R.id.container
),您应该在其中显示片段

<framelayout android:id="@+id/container"/> // this snippet is just for idea.
//这段代码仅供参考。
在主活动xml中没有容器(
R.id.container
),您应该在其中显示片段

<framelayout android:id="@+id/container"/> // this snippet is just for idea.
//这段代码仅供参考。

粘贴片段类。现在我为您的引用添加了代码,并创建了您的片段类。它丢失了。现在我添加了代码供您参考。如果我添加了代码,布局打开了,但太小了,并且在主活动下打开了。您可以设置容器的高度和宽度以正确显示,当然,它将在主活动下显示。片段应该具有父活动。他们不是那样独立的。ohk@vijayg试试看,让我知道。在主活动下显示的页面只是它没有全屏显示如何解决这个问题我已经改变了上面代码中的主活动xml这是我的xml如果我添加代码布局打开了,但太小了,它在主活动下打开了你可以设置容器的高度和宽度要正确显示,当然它将在主活动下显示。片段应该具有父活动。他们不是那样独立的。ohk@vijayg试试看,让我知道。在主活动下显示的页面只是它没有全屏显示如何解决这个问题我已经改变了上面代码中的主活动xml那是我的xml