-5

I have extended 3 fragment in main activity..also how do i add recyclerview to display a list in one of my fragment.

Please help

HSBP
  • 735
  • 2
  • 8
  • 22

2 Answers2

1

Never mind you are begineer :) . Look first of all look how the fragment works.Fragment requires a activity . In activity you have to create framelayout and load or commit fragment in framelayout(Activity).

Now if you want to change any view in the activity you have to change it in fragment and call respective fragment in activity of change its view.

This means you have to add recyclerview in the activity but first off all you must add that fragment containing recyclerview to framelayout of the activity.

taman neupane
  • 938
  • 9
  • 18
  • can you provide some examples related from which i could understand better,the explanation you provided was good but some terms were difficult to understand. – HSBP Jan 04 '17 at 09:12
  • yes i know fragment are quite complex for begineer to understand.For what purpose you are using fragment here?? Are you using nav drawer or tab or anything else?? – taman neupane Jan 04 '17 at 09:14
  • I am using it for Tabs(3 tabs basically). I have extended my main activity to 3 fragments(3 tabs)..so i want create a list in one of fragment using recycler view and recycler adapter. – HSBP Jan 04 '17 at 09:17
  • ok http://www.androhub.com/android-material-design-tabs-using-tablayout/ this might help you. – taman neupane Jan 04 '17 at 09:25
0

You are looking for something like this:

Note: Make sure you add this to your app gradle:

compile 'com.android.support:recyclerview-v7:23.4.0'

You have fragment1.java with layout fragment1.xml: fragment1.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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">
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/fragment1_recycler_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:clickable="true">
                </android.support.v7.widget.RecyclerView>
</RelativeLayout>

Initialize this RecyclerView inside fragment1.java and write is adapter. For more on this, try these links: How to implement RecyclerView with CardView rows in a Fragment with TabLayout http://www.androidhive.info/2016/01/android-working-with-recycler-view/

Community
  • 1
  • 1
Suhayl SH
  • 1,213
  • 1
  • 11
  • 16