我有一个导航抽屉,我试图获取有关在RecycleView上点击的项目的信息。
我的DashboardActiviy布局文件:
<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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
style="@style/AppTabLayout"
app:tabTextAppearance="@style/AppTabTextAppearance"
android:minHeight="0dp"
android:layout_height="0dp"
app:tabMode="fixed"
app:tabGravity="fill"/>
</LinearLayout>
</LinearLayout>
<fragment
android:id="@+id/fragment_navigation_drawer"
android:name="com.oastudios.motosar.fragments.FragmentDrawer"
android:layout_width="@dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_navigation_drawer"
tools:layout="@layout/fragment_navigation_drawer" />
<android.support.v4.view.ViewPager
app:tabGravity="fill"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="56dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.v4.widget.DrawerLayout>
我的DashboardActivity.java:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
......
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
....
}
最后我的适配器onBindViewHolder:
@Override
public void onBindViewHolder(final MyViewHolder holder, int position) {
NavDrawerItem current = data.get(position);
holder.bind(data.get(position), listener);
holder.title.setText(current.getTitle());
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, holder.title.toString(), Toast.LENGTH_LONG).show();
}
});
holder.title.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(context, holder.title.toString(), Toast.LENGTH_LONG).show();
}
});
}
我尝试将textview暴露在onClick或其itemViews onClick上,但它们都不适用于我。
是否存在Z-index问题,因为我可以看到我的NavigationDrawerAdapter正在工作并列出我的菜单元素并正确滑入/滑出,导航菜单图标工作正常但无法使OnClick正常工作。
请帮忙。