Navigation drawer Items not registering click event

后端 未结 6 1027
花落未央
花落未央 2020-12-03 07:30

I am struggling to get the Navigation drawer items to register and start and intent for a new activity. The drawer opens fine and is displayed correctly but nothing happens

相关标签:
6条回答
  • 2020-12-03 07:48

    Fixed a similar issue by adding drawerView.bringToFront(); to

    @Override
    public void onDrawerOpened(View drawerView) {
    
    } 
    
    0 讨论(0)
  • 2020-12-03 07:50

    If you have a list in Navigation Drawer then just write the code and make listview clickable:

    list.bringToFront();
    drawerLayout.requestLayout(); 
    
    0 讨论(0)
  • 2020-12-03 07:53

    I also had a problem with not responding on clicks navigation driver. Somehow I have found a solution: problem was in XML file. I used this and my problem was gone:

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <!-- As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions. -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    
    <!-- android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         The drawer is given a fixed width in dp and extends the full height of
         the container. A solid background is used for contrast
         with the content view. -->
    
    
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#ffff"/>
    

    hope this will be usefull.

    0 讨论(0)
  • 2020-12-03 07:55

    It seems like the your DrawerItemClickListener.class does not work as the only time the selectItem() method is called is at the end of your activities onCreate() at selectItem(0);

    Instead of calling

    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
    

    you can use this as a parameter and let you Activity implement the ListView.OnItemClickListener itself.

    public class MyActivity extends Activity implements ListView.OnItemClickListener {
    
        public void onCreate(Bundle savedInstanceState) {
            [...]
            mDrawerList = (ListView) findViewById(R.id.left_drawer);
    
            [...]
            mDrawerList.setOnItemClickListener(this);
            [...]
         }
    
        [...]    
    
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            selectItem(position);
        }
    
        private void selectItem(int position) {
            switch (position) {
                case 1:
                    [...]
                    startActivity(new Intent(this, SplashScreen.class));
                    break;
                [...]
                default:
                break;
            }
            [...]
        }
        [...]
    }
    
    0 讨论(0)
  • 2020-12-03 07:57

    The problem is the z ordering. When you expand the list in onDrawerOpened put:

    mDrawerList.bringToFront();
    mDrawerLayout.requestLayout();
    

    In this post explain the problem and how fix it: http://vardhan-justlikethat.blogspot.com.es/2014/05/android-custom-navigation-drawer-not.html

    0 讨论(0)
  • 2020-12-03 08:03

    You should check if you have android:animateLayoutChanges="true" attribute on ListView parent(in layout resource). Removing that attribute worked for me.

    0 讨论(0)
提交回复
热议问题