title: Can I create method inside the fragment?
body: <p>I am kind of new to android studio thing. I got some questions to ask. How do I add method locally in fragments and how can I show it in app? I am trying to show my data from existing database with REST API using Retrofit, to show it in Android fragment. I tried different tutorials from YouTube but I am not sure with it.</p>
  <p>This is the code for RecyclerView Adapter:</p>
  <pre><code>    package com.example.cyberview_android1;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.TextView;
  
  import androidx.annotation.NonNull;
  import androidx.recyclerview.widget.RecyclerView;
  
  import java.util.List;
  
  public class RecyclerViewAdapter extends RecyclerView.Adapter&lt;RecyclerViewAdapter.RecyclerHolder&gt; {
  
      List&lt;ProfileModel&gt; models;
  
  
      public RecyclerViewAdapter(List&lt;ProfileModel&gt; models) {
          this.models = models;
      }
  
      @NonNull
      @Override
      public RecyclerHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
          View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.layout_row, viewGroup, false);
          return new RecyclerHolder(view);
      }
  
      @Override
      public void onBindViewHolder(@NonNull RecyclerHolder holder, int position) {
  
          recyclerHolder.textView.setText(models.get(i).profile_cat);
      }
  
      @Override
      public int getItemCount() {
          return models.size();
      }
  
      public class RecyclerHolder extends RecyclerView.ViewHolder {
          TextView textView;
  
          public RecyclerHolder(@NonNull View itemView) {
              super(itemView);
              textView = itemView.findViewById(R.id.textTitle);
          }
      }
  }
  </code></pre>
  <p>This is the code for Fragment:</p>
  <pre><code>package com.example.cyberview_android1;
  
  import android.os.Bundle;
  
  import androidx.annotation.Nullable;
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.LinearLayout;
  
  import java.util.List;
  
  import retrofit2.Call;
  import retrofit2.Callback;
  import retrofit2.Response;
  
  
  public class ProfileFragment extends Fragment {
      RecyclerView rvProfile;
  
  
      public ProfileFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          rvProfile = rvProfile.findViewById(R.id.rv_profile);
          rvProfile.setLayoutManager(new LinearLayoutManager(ProfileFragment.this));
          RetrofitInterface retrofitInterface = RetrofitInstance.getRetrofitInstance().create(RetrofitInterface.class);
          Call&lt;List&lt;ProfileModel&gt;&gt; listCall = retrofitInterface.getAllProfile();
          listCall.enqueue(new Callback&lt;List&lt;ProfileModel&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;ProfileModel&gt;&gt; call, Response&lt;List&lt;ProfileModel&gt;&gt; response) {
                  parseData(response.body());
              }
  
              @Override
              public void onFailure(Call&lt;List&lt;ProfileModel&gt;&gt; call, Throwable t) {
  
              }
          });
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
  
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_profile, container, false);
      }
  
      private void parseData(List&lt;ProfileModel&gt; body) {
          RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(body);
          rvProfile.setAdapter(recyclerViewAdapter);
      }
  }package com.example.cyberview_android1;
  
  import android.os.Bundle;
  
  import androidx.annotation.Nullable;
  import androidx.fragment.app.Fragment;
  import androidx.recyclerview.widget.LinearLayoutManager;
  import androidx.recyclerview.widget.RecyclerView;
  
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.LinearLayout;
  
  import java.util.List;
  
  import retrofit2.Call;
  import retrofit2.Callback;
  import retrofit2.Response;
  
  
  public class ProfileFragment extends Fragment {
      RecyclerView rvProfile;
  
  
      public ProfileFragment() {
          // Required empty public constructor
      }
  
      @Override
      public void onCreate(@Nullable Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          rvProfile = rvProfile.findViewById(R.id.rv_profile);
          rvProfile.setLayoutManager(new LinearLayoutManager(ProfileFragment.this));
          RetrofitInterface retrofitInterface = RetrofitInstance.getRetrofitInstance().create(RetrofitInterface.class);
          Call&lt;List&lt;ProfileModel&gt;&gt; listCall = retrofitInterface.getAllProfile();
          listCall.enqueue(new Callback&lt;List&lt;ProfileModel&gt;&gt;() {
              @Override
              public void onResponse(Call&lt;List&lt;ProfileModel&gt;&gt; call, Response&lt;List&lt;ProfileModel&gt;&gt; response) {
                  parseData(response.body());
              }
  
              @Override
              public void onFailure(Call&lt;List&lt;ProfileModel&gt;&gt; call, Throwable t) {
  
              }
          });
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
  
  
          // Inflate the layout for this fragment
          return inflater.inflate(R.layout.fragment_profile, container, false);
      }
  
      private void parseData(List&lt;ProfileModel&gt; body) {
          RecyclerViewAdapter recyclerViewAdapter = new RecyclerViewAdapter(body);
          rvProfile.setAdapter(recyclerViewAdapter);
      }
  }
  </code></pre>
  <p>This is the retrofit instance code:</p>
  <pre><code>package com.example.cyberview_android1;
  
  import retrofit2.Retrofit;
  import retrofit2.converter.gson.GsonConverterFactory;
  
  public class RetrofitInstance {
  
      private static Retrofit retrofit;
      private static final String BASE_URL = &quot;http://localhost:5000/api/&quot;;
  
      public static Retrofit getRetrofitInstance() {
          if (retrofit == null) {
              retrofit = new retrofit2.Retrofit.Builder()
                      .baseUrl(BASE_URL)
                      .addConverterFactory(GsonConverterFactory.create())
                      .build();
          }
          return retrofit;
      }
  
  
  }
  </code></pre>
  <p>The interface:</p>
  <pre><code>package com.example.cyberview_android1;
  
  import java.util.List;
  
  import retrofit2.Call;
  import retrofit2.http.GET;
  
  public interface RetrofitInterface {
  
      @GET(&quot;/employee/profile&quot;)
      Call&lt;List&lt;ProfileModel&gt;&gt; getAllProfile();
  
  
  }
  </code></pre>
  <p>And the model:</p>
  <pre><code>package com.example.cyberview_android1;
  
  import com.google.gson.annotations.SerializedName;
  
  public class ProfileModel {
  
      @SerializedName(&quot;category&quot;)
      String profile_cat;
  
      @SerializedName(&quot;description&quot;)
      String profile_desc;
  
      @SerializedName(&quot;date&quot;)
      String date;
  
      public String getProfile_cat() {
          return profile_cat;
      }
  
      public void setProfile_cat(String profile_cat) {
          this.profile_cat = profile_cat;
      }
  
      public String getProfile_desc() {
          return profile_desc;
      }
  
      public void setProfile_desc(String profile_desc) {
          this.profile_desc = profile_desc;
      }
  
      public String getDate() {
          return date;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  }
  </code></pre>
  <p>Additionally, I am getting an error from the Holders and View groups. I followed the steps from the tutorial but I assure that I didnt miss anything from it.</p>
  <p><a href="https://i.stack.imgur.com/tRPbx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tRPbx.png" alt="enter image description here" /></a></p>
  <p>I would really appreciate your help.</p>