在导航抽屉中进行交互时,Cardslib片段无响应

时间:2014-07-09 14:48:45

标签: android cardslib

我遇到问题的片段是使用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();
}

NoteFragment返回膨胀的布局:

@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);
}

Container 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>

Fragment 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>

感谢任何帮助。

1 个答案:

答案 0 :(得分:3)

我修好了! onCreateView()中的Cardslib代码段被移动到onStart(),它修复了无响应。