I am not able to see the grid view in my Bookmark which extends Fragment












0















I am facing an issue the problem is I can see the Fragment but not the
GridView which I have there created, in the LogCat no error nothing but somehow the code it is not working.
But if I remove GridView from bookmark.xml and only leave a TextView than I can show the TextView
I am trying to reach a GridView into a Fragment.
This is my code.



Fragment



public class FragmentBookmark extends Fragment {
View paramView;
public FragmentBookmark() {
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

paramView = inflater.inflate(R.layout.bookmark, container, false);
return paramView;
}

}


This is the Main Activity



 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentExplore(), "");
adapter.AddFragment(new FragmentBookmark(), "");
adapter.AddFragment(new FragmentStore(), "");
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);


This is the xml for Bookmark Fragment



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</LinearLayout>









share|improve this question

























  • have you used .setAdapter?

    – Rumit Patel
    Nov 22 '18 at 12:35











  • What do you think .setAdapter because I am new in android ? can you explain more or edit my code

    – Spritzig
    Nov 22 '18 at 12:38











  • If you are new, I would suggest you to use RecyclerView. because GridView is old.

    – Rumit Patel
    Nov 22 '18 at 12:40











  • Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

    – Spritzig
    Nov 22 '18 at 12:41











  • you can have a look my answer below.

    – Rumit Patel
    Nov 22 '18 at 12:58
















0















I am facing an issue the problem is I can see the Fragment but not the
GridView which I have there created, in the LogCat no error nothing but somehow the code it is not working.
But if I remove GridView from bookmark.xml and only leave a TextView than I can show the TextView
I am trying to reach a GridView into a Fragment.
This is my code.



Fragment



public class FragmentBookmark extends Fragment {
View paramView;
public FragmentBookmark() {
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

paramView = inflater.inflate(R.layout.bookmark, container, false);
return paramView;
}

}


This is the Main Activity



 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentExplore(), "");
adapter.AddFragment(new FragmentBookmark(), "");
adapter.AddFragment(new FragmentStore(), "");
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);


This is the xml for Bookmark Fragment



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</LinearLayout>









share|improve this question

























  • have you used .setAdapter?

    – Rumit Patel
    Nov 22 '18 at 12:35











  • What do you think .setAdapter because I am new in android ? can you explain more or edit my code

    – Spritzig
    Nov 22 '18 at 12:38











  • If you are new, I would suggest you to use RecyclerView. because GridView is old.

    – Rumit Patel
    Nov 22 '18 at 12:40











  • Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

    – Spritzig
    Nov 22 '18 at 12:41











  • you can have a look my answer below.

    – Rumit Patel
    Nov 22 '18 at 12:58














0












0








0








I am facing an issue the problem is I can see the Fragment but not the
GridView which I have there created, in the LogCat no error nothing but somehow the code it is not working.
But if I remove GridView from bookmark.xml and only leave a TextView than I can show the TextView
I am trying to reach a GridView into a Fragment.
This is my code.



Fragment



public class FragmentBookmark extends Fragment {
View paramView;
public FragmentBookmark() {
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

paramView = inflater.inflate(R.layout.bookmark, container, false);
return paramView;
}

}


This is the Main Activity



 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentExplore(), "");
adapter.AddFragment(new FragmentBookmark(), "");
adapter.AddFragment(new FragmentStore(), "");
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);


This is the xml for Bookmark Fragment



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</LinearLayout>









share|improve this question
















I am facing an issue the problem is I can see the Fragment but not the
GridView which I have there created, in the LogCat no error nothing but somehow the code it is not working.
But if I remove GridView from bookmark.xml and only leave a TextView than I can show the TextView
I am trying to reach a GridView into a Fragment.
This is my code.



Fragment



public class FragmentBookmark extends Fragment {
View paramView;
public FragmentBookmark() {
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

paramView = inflater.inflate(R.layout.bookmark, container, false);
return paramView;
}

}


This is the Main Activity



 ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.AddFragment(new FragmentExplore(), "");
adapter.AddFragment(new FragmentBookmark(), "");
adapter.AddFragment(new FragmentStore(), "");
mViewPager.setAdapter(adapter);
mTabLayout.setupWithViewPager(mViewPager);


This is the xml for Bookmark Fragment



<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">

<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="auto_fit"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
/>

</LinearLayout>






android xml android-fragments






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 13:47









Savin Sharma

426315




426315










asked Nov 22 '18 at 12:11









SpritzigSpritzig

1491215




1491215













  • have you used .setAdapter?

    – Rumit Patel
    Nov 22 '18 at 12:35











  • What do you think .setAdapter because I am new in android ? can you explain more or edit my code

    – Spritzig
    Nov 22 '18 at 12:38











  • If you are new, I would suggest you to use RecyclerView. because GridView is old.

    – Rumit Patel
    Nov 22 '18 at 12:40











  • Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

    – Spritzig
    Nov 22 '18 at 12:41











  • you can have a look my answer below.

    – Rumit Patel
    Nov 22 '18 at 12:58



















  • have you used .setAdapter?

    – Rumit Patel
    Nov 22 '18 at 12:35











  • What do you think .setAdapter because I am new in android ? can you explain more or edit my code

    – Spritzig
    Nov 22 '18 at 12:38











  • If you are new, I would suggest you to use RecyclerView. because GridView is old.

    – Rumit Patel
    Nov 22 '18 at 12:40











  • Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

    – Spritzig
    Nov 22 '18 at 12:41











  • you can have a look my answer below.

    – Rumit Patel
    Nov 22 '18 at 12:58

















have you used .setAdapter?

– Rumit Patel
Nov 22 '18 at 12:35





have you used .setAdapter?

– Rumit Patel
Nov 22 '18 at 12:35













What do you think .setAdapter because I am new in android ? can you explain more or edit my code

– Spritzig
Nov 22 '18 at 12:38





What do you think .setAdapter because I am new in android ? can you explain more or edit my code

– Spritzig
Nov 22 '18 at 12:38













If you are new, I would suggest you to use RecyclerView. because GridView is old.

– Rumit Patel
Nov 22 '18 at 12:40





If you are new, I would suggest you to use RecyclerView. because GridView is old.

– Rumit Patel
Nov 22 '18 at 12:40













Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

– Spritzig
Nov 22 '18 at 12:41





Thank you for the answer, if you have any suggestion what to do please edit my code or make an answer

– Spritzig
Nov 22 '18 at 12:41













you can have a look my answer below.

– Rumit Patel
Nov 22 '18 at 12:58





you can have a look my answer below.

– Rumit Patel
Nov 22 '18 at 12:58












3 Answers
3






active

oldest

votes


















0














Try like this using framelayout



<FrameLayout
xmlns:android = "http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<GridView
android:id = "@+id/gvList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:verticalSpacing="0dp"
android:horizontalSpacing="0dp"
android:stretchMode="spacingWidth"
android:numColumns="2"/>
</FrameLayout>





share|improve this answer































    0














    You need to set adapter to your GridView as only GridView will never show anything as it is a simple ViewGroup.. Also rather than using GridView try to use RecyclerView in grid mode. Below is a simple tutorial you can follow-
    RecyclerView as GridView with GridLayoutManager






    share|improve this answer































      0














      xml:



      <?xml version="1.0" encoding="utf-8"?>
      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

      <android.support.v7.widget.RecyclerView
      android:id="@+id/m_recyclerView"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_margin="4dp" />
      </LinearLayout>


      grid_item.xml



      <?xml version="1.0" encoding="utf-8"?>
      <android.support.v7.widget.CardView 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:layout_width="match_parent"
      android:layout_height="wrap_content"
      app:cardElevation="4dp">

      <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:orientation="vertical">

      <ImageView
      android:id="@+id/imageview1"
      android:layout_width="50dp"
      android:layout_height="50dp"
      android:layout_margin="5dp"
      android:contentDescription="@null" />

      <TextView
      android:id="@+id/tv_name"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:gravity="center"
      android:maxLines="1"
      android:singleLine="true"
      tools:text="Category" />
      </LinearLayout>
      </android.support.v7.widget.CardView>


      Adapter:



      import android.content.Context;
      import android.support.annotation.NonNull;
      import android.support.v7.widget.RecyclerView;
      import android.view.LayoutInflater;
      import android.view.View;
      import android.view.ViewGroup;
      import android.widget.TextView;
      import java.util.List;

      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

      private Context mContext;
      private List<String> myNameList;

      public MyAdapter(Context context, List<String> categoryInfo) {
      mContext = context;
      myNameList = categoryInfo;
      }

      @NonNull
      @Override
      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
      return new MyViewHolder(view);
      }

      @Override
      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
      String myName = myNameList.get(position);
      holder.tvName.setText(myName);
      }

      @Override
      public int getItemCount() {
      return myNameList.size();
      }

      class MyViewHolder extends RecyclerView.ViewHolder {
      private TextView tvName;

      MyViewHolder(View itemView) {
      super(itemView);
      tvName = itemView.findViewById(R.id.tv_name);
      }
      }
      }


      In your Activity or Fragment:



      Context mContext = this;
      RecyclerView mRecyclerView;
      mRecyclerView = findViewById(R.id.m_recyclerView);
      mRecyclerView.setLayoutManager(new android.support.v7.widget.GridLayoutManager(mContext, 3));

      ArrayList<String> nameArray = new ArrayList<>();
      nameArray.add("name 1");
      nameArray.add("name 2");
      nameArray.add("name 3");
      nameArray.add("name 4");

      mRecyclerView.setAdapter(new MyAdapter(mContext, nameArray));





      share|improve this answer


























      • The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

        – Spritzig
        Nov 22 '18 at 13:05













      • in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

        – Rumit Patel
        Nov 22 '18 at 13:08











      • It is not working man ?

        – Spritzig
        Nov 22 '18 at 13:12











      • what data you entered in yourStringArrayList?

        – Rumit Patel
        Nov 22 '18 at 13:15











      • Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

        – Spritzig
        Nov 22 '18 at 13:17











      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430755%2fi-am-not-able-to-see-the-grid-view-in-my-bookmark-which-extends-fragment%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      Try like this using framelayout



      <FrameLayout
      xmlns:android = "http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      >
      <GridView
      android:id = "@+id/gvList"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:verticalSpacing="0dp"
      android:horizontalSpacing="0dp"
      android:stretchMode="spacingWidth"
      android:numColumns="2"/>
      </FrameLayout>





      share|improve this answer




























        0














        Try like this using framelayout



        <FrameLayout
        xmlns:android = "http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
        <GridView
        android:id = "@+id/gvList"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:verticalSpacing="0dp"
        android:horizontalSpacing="0dp"
        android:stretchMode="spacingWidth"
        android:numColumns="2"/>
        </FrameLayout>





        share|improve this answer


























          0












          0








          0







          Try like this using framelayout



          <FrameLayout
          xmlns:android = "http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          >
          <GridView
          android:id = "@+id/gvList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:verticalSpacing="0dp"
          android:horizontalSpacing="0dp"
          android:stretchMode="spacingWidth"
          android:numColumns="2"/>
          </FrameLayout>





          share|improve this answer













          Try like this using framelayout



          <FrameLayout
          xmlns:android = "http://schemas.android.com/apk/res/android"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          >
          <GridView
          android:id = "@+id/gvList"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:verticalSpacing="0dp"
          android:horizontalSpacing="0dp"
          android:stretchMode="spacingWidth"
          android:numColumns="2"/>
          </FrameLayout>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 12:18









          Sunil PSunil P

          1,3072616




          1,3072616

























              0














              You need to set adapter to your GridView as only GridView will never show anything as it is a simple ViewGroup.. Also rather than using GridView try to use RecyclerView in grid mode. Below is a simple tutorial you can follow-
              RecyclerView as GridView with GridLayoutManager






              share|improve this answer




























                0














                You need to set adapter to your GridView as only GridView will never show anything as it is a simple ViewGroup.. Also rather than using GridView try to use RecyclerView in grid mode. Below is a simple tutorial you can follow-
                RecyclerView as GridView with GridLayoutManager






                share|improve this answer


























                  0












                  0








                  0







                  You need to set adapter to your GridView as only GridView will never show anything as it is a simple ViewGroup.. Also rather than using GridView try to use RecyclerView in grid mode. Below is a simple tutorial you can follow-
                  RecyclerView as GridView with GridLayoutManager






                  share|improve this answer













                  You need to set adapter to your GridView as only GridView will never show anything as it is a simple ViewGroup.. Also rather than using GridView try to use RecyclerView in grid mode. Below is a simple tutorial you can follow-
                  RecyclerView as GridView with GridLayoutManager







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 22 '18 at 12:20









                  saurabh169saurabh169

                  6410




                  6410























                      0














                      xml:



                      <?xml version="1.0" encoding="utf-8"?>
                      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:orientation="vertical">

                      <android.support.v7.widget.RecyclerView
                      android:id="@+id/m_recyclerView"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_margin="4dp" />
                      </LinearLayout>


                      grid_item.xml



                      <?xml version="1.0" encoding="utf-8"?>
                      <android.support.v7.widget.CardView 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:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      app:cardElevation="4dp">

                      <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:orientation="vertical">

                      <ImageView
                      android:id="@+id/imageview1"
                      android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:layout_margin="5dp"
                      android:contentDescription="@null" />

                      <TextView
                      android:id="@+id/tv_name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:maxLines="1"
                      android:singleLine="true"
                      tools:text="Category" />
                      </LinearLayout>
                      </android.support.v7.widget.CardView>


                      Adapter:



                      import android.content.Context;
                      import android.support.annotation.NonNull;
                      import android.support.v7.widget.RecyclerView;
                      import android.view.LayoutInflater;
                      import android.view.View;
                      import android.view.ViewGroup;
                      import android.widget.TextView;
                      import java.util.List;

                      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

                      private Context mContext;
                      private List<String> myNameList;

                      public MyAdapter(Context context, List<String> categoryInfo) {
                      mContext = context;
                      myNameList = categoryInfo;
                      }

                      @NonNull
                      @Override
                      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
                      return new MyViewHolder(view);
                      }

                      @Override
                      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
                      String myName = myNameList.get(position);
                      holder.tvName.setText(myName);
                      }

                      @Override
                      public int getItemCount() {
                      return myNameList.size();
                      }

                      class MyViewHolder extends RecyclerView.ViewHolder {
                      private TextView tvName;

                      MyViewHolder(View itemView) {
                      super(itemView);
                      tvName = itemView.findViewById(R.id.tv_name);
                      }
                      }
                      }


                      In your Activity or Fragment:



                      Context mContext = this;
                      RecyclerView mRecyclerView;
                      mRecyclerView = findViewById(R.id.m_recyclerView);
                      mRecyclerView.setLayoutManager(new android.support.v7.widget.GridLayoutManager(mContext, 3));

                      ArrayList<String> nameArray = new ArrayList<>();
                      nameArray.add("name 1");
                      nameArray.add("name 2");
                      nameArray.add("name 3");
                      nameArray.add("name 4");

                      mRecyclerView.setAdapter(new MyAdapter(mContext, nameArray));





                      share|improve this answer


























                      • The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                        – Spritzig
                        Nov 22 '18 at 13:05













                      • in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                        – Rumit Patel
                        Nov 22 '18 at 13:08











                      • It is not working man ?

                        – Spritzig
                        Nov 22 '18 at 13:12











                      • what data you entered in yourStringArrayList?

                        – Rumit Patel
                        Nov 22 '18 at 13:15











                      • Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                        – Spritzig
                        Nov 22 '18 at 13:17
















                      0














                      xml:



                      <?xml version="1.0" encoding="utf-8"?>
                      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:orientation="vertical">

                      <android.support.v7.widget.RecyclerView
                      android:id="@+id/m_recyclerView"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_margin="4dp" />
                      </LinearLayout>


                      grid_item.xml



                      <?xml version="1.0" encoding="utf-8"?>
                      <android.support.v7.widget.CardView 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:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      app:cardElevation="4dp">

                      <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:orientation="vertical">

                      <ImageView
                      android:id="@+id/imageview1"
                      android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:layout_margin="5dp"
                      android:contentDescription="@null" />

                      <TextView
                      android:id="@+id/tv_name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:maxLines="1"
                      android:singleLine="true"
                      tools:text="Category" />
                      </LinearLayout>
                      </android.support.v7.widget.CardView>


                      Adapter:



                      import android.content.Context;
                      import android.support.annotation.NonNull;
                      import android.support.v7.widget.RecyclerView;
                      import android.view.LayoutInflater;
                      import android.view.View;
                      import android.view.ViewGroup;
                      import android.widget.TextView;
                      import java.util.List;

                      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

                      private Context mContext;
                      private List<String> myNameList;

                      public MyAdapter(Context context, List<String> categoryInfo) {
                      mContext = context;
                      myNameList = categoryInfo;
                      }

                      @NonNull
                      @Override
                      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
                      return new MyViewHolder(view);
                      }

                      @Override
                      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
                      String myName = myNameList.get(position);
                      holder.tvName.setText(myName);
                      }

                      @Override
                      public int getItemCount() {
                      return myNameList.size();
                      }

                      class MyViewHolder extends RecyclerView.ViewHolder {
                      private TextView tvName;

                      MyViewHolder(View itemView) {
                      super(itemView);
                      tvName = itemView.findViewById(R.id.tv_name);
                      }
                      }
                      }


                      In your Activity or Fragment:



                      Context mContext = this;
                      RecyclerView mRecyclerView;
                      mRecyclerView = findViewById(R.id.m_recyclerView);
                      mRecyclerView.setLayoutManager(new android.support.v7.widget.GridLayoutManager(mContext, 3));

                      ArrayList<String> nameArray = new ArrayList<>();
                      nameArray.add("name 1");
                      nameArray.add("name 2");
                      nameArray.add("name 3");
                      nameArray.add("name 4");

                      mRecyclerView.setAdapter(new MyAdapter(mContext, nameArray));





                      share|improve this answer


























                      • The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                        – Spritzig
                        Nov 22 '18 at 13:05













                      • in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                        – Rumit Patel
                        Nov 22 '18 at 13:08











                      • It is not working man ?

                        – Spritzig
                        Nov 22 '18 at 13:12











                      • what data you entered in yourStringArrayList?

                        – Rumit Patel
                        Nov 22 '18 at 13:15











                      • Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                        – Spritzig
                        Nov 22 '18 at 13:17














                      0












                      0








                      0







                      xml:



                      <?xml version="1.0" encoding="utf-8"?>
                      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:orientation="vertical">

                      <android.support.v7.widget.RecyclerView
                      android:id="@+id/m_recyclerView"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_margin="4dp" />
                      </LinearLayout>


                      grid_item.xml



                      <?xml version="1.0" encoding="utf-8"?>
                      <android.support.v7.widget.CardView 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:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      app:cardElevation="4dp">

                      <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:orientation="vertical">

                      <ImageView
                      android:id="@+id/imageview1"
                      android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:layout_margin="5dp"
                      android:contentDescription="@null" />

                      <TextView
                      android:id="@+id/tv_name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:maxLines="1"
                      android:singleLine="true"
                      tools:text="Category" />
                      </LinearLayout>
                      </android.support.v7.widget.CardView>


                      Adapter:



                      import android.content.Context;
                      import android.support.annotation.NonNull;
                      import android.support.v7.widget.RecyclerView;
                      import android.view.LayoutInflater;
                      import android.view.View;
                      import android.view.ViewGroup;
                      import android.widget.TextView;
                      import java.util.List;

                      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

                      private Context mContext;
                      private List<String> myNameList;

                      public MyAdapter(Context context, List<String> categoryInfo) {
                      mContext = context;
                      myNameList = categoryInfo;
                      }

                      @NonNull
                      @Override
                      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
                      return new MyViewHolder(view);
                      }

                      @Override
                      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
                      String myName = myNameList.get(position);
                      holder.tvName.setText(myName);
                      }

                      @Override
                      public int getItemCount() {
                      return myNameList.size();
                      }

                      class MyViewHolder extends RecyclerView.ViewHolder {
                      private TextView tvName;

                      MyViewHolder(View itemView) {
                      super(itemView);
                      tvName = itemView.findViewById(R.id.tv_name);
                      }
                      }
                      }


                      In your Activity or Fragment:



                      Context mContext = this;
                      RecyclerView mRecyclerView;
                      mRecyclerView = findViewById(R.id.m_recyclerView);
                      mRecyclerView.setLayoutManager(new android.support.v7.widget.GridLayoutManager(mContext, 3));

                      ArrayList<String> nameArray = new ArrayList<>();
                      nameArray.add("name 1");
                      nameArray.add("name 2");
                      nameArray.add("name 3");
                      nameArray.add("name 4");

                      mRecyclerView.setAdapter(new MyAdapter(mContext, nameArray));





                      share|improve this answer















                      xml:



                      <?xml version="1.0" encoding="utf-8"?>
                      <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:orientation="vertical">

                      <android.support.v7.widget.RecyclerView
                      android:id="@+id/m_recyclerView"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:layout_margin="4dp" />
                      </LinearLayout>


                      grid_item.xml



                      <?xml version="1.0" encoding="utf-8"?>
                      <android.support.v7.widget.CardView 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:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      app:cardElevation="4dp">

                      <LinearLayout
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:orientation="vertical">

                      <ImageView
                      android:id="@+id/imageview1"
                      android:layout_width="50dp"
                      android:layout_height="50dp"
                      android:layout_margin="5dp"
                      android:contentDescription="@null" />

                      <TextView
                      android:id="@+id/tv_name"
                      android:layout_width="match_parent"
                      android:layout_height="wrap_content"
                      android:gravity="center"
                      android:maxLines="1"
                      android:singleLine="true"
                      tools:text="Category" />
                      </LinearLayout>
                      </android.support.v7.widget.CardView>


                      Adapter:



                      import android.content.Context;
                      import android.support.annotation.NonNull;
                      import android.support.v7.widget.RecyclerView;
                      import android.view.LayoutInflater;
                      import android.view.View;
                      import android.view.ViewGroup;
                      import android.widget.TextView;
                      import java.util.List;

                      public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MyViewHolder> {

                      private Context mContext;
                      private List<String> myNameList;

                      public MyAdapter(Context context, List<String> categoryInfo) {
                      mContext = context;
                      myNameList = categoryInfo;
                      }

                      @NonNull
                      @Override
                      public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
                      View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.grid_item, parent, false);
                      return new MyViewHolder(view);
                      }

                      @Override
                      public void onBindViewHolder(@NonNull MyViewHolder holder, final int position) {
                      String myName = myNameList.get(position);
                      holder.tvName.setText(myName);
                      }

                      @Override
                      public int getItemCount() {
                      return myNameList.size();
                      }

                      class MyViewHolder extends RecyclerView.ViewHolder {
                      private TextView tvName;

                      MyViewHolder(View itemView) {
                      super(itemView);
                      tvName = itemView.findViewById(R.id.tv_name);
                      }
                      }
                      }


                      In your Activity or Fragment:



                      Context mContext = this;
                      RecyclerView mRecyclerView;
                      mRecyclerView = findViewById(R.id.m_recyclerView);
                      mRecyclerView.setLayoutManager(new android.support.v7.widget.GridLayoutManager(mContext, 3));

                      ArrayList<String> nameArray = new ArrayList<>();
                      nameArray.add("name 1");
                      nameArray.add("name 2");
                      nameArray.add("name 3");
                      nameArray.add("name 4");

                      mRecyclerView.setAdapter(new MyAdapter(mContext, nameArray));






                      share|improve this answer














                      share|improve this answer



                      share|improve this answer








                      edited Nov 22 '18 at 13:55

























                      answered Nov 22 '18 at 12:58









                      Rumit PatelRumit Patel

                      1,83152435




                      1,83152435













                      • The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                        – Spritzig
                        Nov 22 '18 at 13:05













                      • in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                        – Rumit Patel
                        Nov 22 '18 at 13:08











                      • It is not working man ?

                        – Spritzig
                        Nov 22 '18 at 13:12











                      • what data you entered in yourStringArrayList?

                        – Rumit Patel
                        Nov 22 '18 at 13:15











                      • Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                        – Spritzig
                        Nov 22 '18 at 13:17



















                      • The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                        – Spritzig
                        Nov 22 '18 at 13:05













                      • in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                        – Rumit Patel
                        Nov 22 '18 at 13:08











                      • It is not working man ?

                        – Spritzig
                        Nov 22 '18 at 13:12











                      • what data you entered in yourStringArrayList?

                        – Rumit Patel
                        Nov 22 '18 at 13:15











                      • Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                        – Spritzig
                        Nov 22 '18 at 13:17

















                      The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                      – Spritzig
                      Nov 22 '18 at 13:05







                      The Activity what you have write in which of my java class I need to implement and the @dimens from xml where I need to import because the are unknow ?

                      – Spritzig
                      Nov 22 '18 at 13:05















                      in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                      – Rumit Patel
                      Nov 22 '18 at 13:08





                      in onCreateView method of FragmentBookmark. or in onCreate method of MainActivity

                      – Rumit Patel
                      Nov 22 '18 at 13:08













                      It is not working man ?

                      – Spritzig
                      Nov 22 '18 at 13:12





                      It is not working man ?

                      – Spritzig
                      Nov 22 '18 at 13:12













                      what data you entered in yourStringArrayList?

                      – Rumit Patel
                      Nov 22 '18 at 13:15





                      what data you entered in yourStringArrayList?

                      – Rumit Patel
                      Nov 22 '18 at 13:15













                      Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                      – Spritzig
                      Nov 22 '18 at 13:17





                      Nothing, but I have another errors for example @dimens and it is oke where I put the Acitivity shows me only errors can you please change all my code with your actual code and see if it works.

                      – Spritzig
                      Nov 22 '18 at 13:17


















                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53430755%2fi-am-not-able-to-see-the-grid-view-in-my-bookmark-which-extends-fragment%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                      SQL update select statement

                      'app-layout' is not a known element: how to share Component with different Modules