0

i already created a navigation drawer bar with a menu but i want to highlight and disable the selected item on the menu bar when i check the drawer bar.

how can i do that ?

also i did not see the click animation when i click the item on the menu

please help

Thanks.

this is the code i used

mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
        @Override
        public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {
            View child = recyclerView.findChildViewUnder(motionEvent.getX(),motionEvent.getY());



            if(child!=null && mGestureDetector.onTouchEvent(motionEvent)){
                Drawer.closeDrawers();
                Toast.makeText(MainActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT).show();


                int pos = recyclerView.getChildPosition(child);

                if(pos== 1){
                    Intent intent = new Intent(getApplicationContext(),About.class);
                    startActivity(intent);
                }

                return true;

            }

            return false;
        }

        @Override
        public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) {

        }

        @Override
        public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {

        }
    });
  • I think you can find the answer [Here](http://stackoverflow.com/questions/29983848/how-to-highlight-the-selected-item-of-recycler-view) :) – Ye Min Htut Jul 20 '15 at 04:08

1 Answers1

0

RecyclerView does not handle item selection or states like a ListView does. Instead you have to handle this manually in your view holder.

The first thing you can do is declare your item view as clickable, in your `ViewHolder constructor :

public ViewHolder(View itemView) { super(itemView);

// Make this view clickable
itemView.setClickable(true);

// ...

}

http://www.grokkingandroid.com/statelistdrawables-for-recyclerview-selection/

NovusMobile
  • 1,813
  • 2
  • 21
  • 48