Posts

Showing posts from October, 2016

Implement Click Listener on RecyclerView

Image
In this post Implement click listener on RecyclerView I put the code after the RecyclerView setAdapter for click listener on RecyclerView following :- final GestureDetector mGestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); recyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { View child = recyclerView.findChildViewUnder(e.getX(), e.getY()); if (child != null && mGestureDetector.onTouchEvent(e)) { int a=recyclerView.getChildPosition(child); Toast. makeText (MainActivity.this, fruit[a], Toast. LENGTH_SHORT ).show(); } return true; } @Override public void onTouchEvent(RecyclerView rv, MotionEvent e) { } @Override public v...

Implement RecyclerVIew in Android

Image
First you can create new project in Android Studio. In this you can create one more xml file and java file. Because RecyclerView  Accept only RecyclerView adapter that why we create another file for REcyclerView Apter class.   After that open the build,gradle(Module:app) and add the following Dependency:-               compile ' com.android.support:recyclerview-v7:24.2.1' After that add the RecyclerView Tag into avtivity_main.xml file between the Layout Tag likew that :-              <android.support.v7.widget.RecyclerView android :id= "@+id/recyclerView" android :layout_width= "match_parent" android :layout_height= "match_parent" /> Open the MainActivity file and declare the RecuclerView and assign the Id to the variable. Now i show you the code in MainActivity.class file  following :- public class MainActivity extends AppCompatActivity { //Decl...

AddThis