簡體   English   中英

在導航抽屜中進行交互時,Cardslib片段沒有響應

[英]Cardslib Fragment not responding when interacted in Navigation Drawer

我遇到問題的片段是使用Cardslib庫中的CardListView。 我將片段動態添加到了容器中,並且一切都按預期工作,除了它與之交互時沒有響應。 這意味着它不會滾動,我無法按下任何卡,以及與該問題有關的其他任何東西。

在MainActivity中向容器添加片段:

@Override
protected void onCreate(Bundle savedInstanceState) {

    // Code here...

    NoteFragment nf = new NoteFragment();
    // nf.setArguments(getIntent().getExtras());

    FragmentTransaction tx = getFragmentManager().beginTransaction();
    tx.add(R.id.container, nf);
    tx.commit();
}

在MainActivity中使用Navigation Drawer時替換容器片段。 選擇的默認大小寫為NoteFragment。

@Override
public void onNavigationDrawerItemSelected(int position) {
    // update the main content by replacing fragments
    Fragment fragment = null;
    switch(position) {
        case 0:
            onSectionAttached(0);
            fragment = new NoteFragment();
            break;
        case 1:
            onSectionAttached(1);
            fragment = new ArchiveFragment();
            break;
        case 2:
            onSectionAttached(2);
            fragment = new TrashFragment();
            break;
    }

    FragmentTransaction tx = getFragmentManager().beginTransaction();
    tx.replace(R.id.container, fragment);
    tx.commit();
}

注意片段返回膨脹的布局:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // CardListView Code Here...

    // Inflate the layout for this fragment
    return inflater.inflate(R.layout.fragment_note, container, false);
}

容器XML(activity_main.xml):

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The drawer is given a fixed width in dp and extends the full height of
         the container. -->
    <fragment android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:name="com.example.NavigationDrawerFragment"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

片段XML(fragment_note.xml):

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.NoteFragment">

    <it.gmariotti.cardslib.library.view.CardListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:paddingTop="5dp"
        android:id="@+id/CardList"/>

</FrameLayout>

任何幫助表示贊賞。

我修好了它! onCreateView()中的Cardslib代碼段已移至onStart(),並修復了無響應。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM