title: How to set value for textview of fragment received from another fragment?
body: <p>I don't know how to set in the textview of second fragment when received the value from another fragment. The data I received in the second fragment is the <strong>"value"</strong> object of StringList but I don't now how to set the data for it.</p>
  
  <p>StringList class:</p>
  
  <pre><code>public class StringList {
  
      public String authorName;
      public String headline;
      public String publishedTime;
      public String newsDetail;
  
  }
  </code></pre>
  
  <p>MainActivity:</p>
  
  <pre><code>//only useful code pasted below for tranfering thre value from fragment to another fragment and i have implemented the TransferValue to the mainActivity
  
          public void sendValue(StringList value, int positionValue) {
  
              FragmentTransaction transaction = frag.beginTransaction();
              BusinessDetail businessDetail = new BusinessDetail();
              businessDetail.receiveValue(value, positionValue);
              transaction.replace(R.id.content_frame, businessDetail);
              transaction.commit();
  
          }
  </code></pre>
  
  <p>Fragment1:</p>
  
  <pre><code>    public class Business extends Fragment  {
  
          public List&lt;StringList&gt; businessNews = new ArrayList&lt;&gt;();
  
          TransferValue SendData;//here
  
          private RecyclerView recyclerView;
           public Business() {
  
          }
  
          @Override
          public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                   Bundle savedInstanceState) {
  
              View view = inflater.inflate(R.layout.fragment_business, container, false);
              recyclerView = (RecyclerView) view.findViewById(R.id.business_recycler_view);
  
              FetchLists f = new FetchLists();
              f.execute(10, 0);
              return view;
          }
  
          @Override
          public void onCreate(@Nullable Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
          }
  
          @Override
          public void onAttach(Context context) {
              super.onAttach(context);
      //here
              try {
                  SendData = (TransferValue) context;
              } catch (ClassCastException e) {
                  Log.d("ashu", "implement the methods");
                  throw new ClassCastException("implemented the methods");
              }
          }
  
  //here
          public interface TransferValue {
  
              public void sendValue(StringList value, int positionValue);
  
          }
  
          public class FetchLists extends AsyncTask&lt;Integer, Void, List&lt;StringList&gt;&gt; {
  
              @Override
              protected List&lt;StringList&gt; doInBackground(Integer... params) {
  
                  int count = params[0];
                  int offset = params[1];
      //api key changed
                  String urlString = "https://newspi.og/v1/article?source=bloomerg&amp;sortBy=tp&amp;apiKey=5fdfd54f4aba5a5fdfvdf476ff528a8";
                  urlString = urlString + "&amp;count=" + count + "&amp;offset=" + offset;
  
                  try {
                      URL url = new URL(urlString);
                      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
                      connection.setRequestMethod("GET");
                      InputStream stream = connection.getInputStream();
                      BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
                      String line = reader.readLine();
                      String response = "";
                      while (line != null) {
                          response += line;
                          line = reader.readLine();
                      }
  
                      JSONObject object = new JSONObject(response);
                      JSONArray emailLists = object.getJSONArray("articles");
  
                      for (int i = 0; i &lt; emailLists.length(); i++) {
                          JSONObject listData = (JSONObject) emailLists.get(i);
  
                          StringList stringList = new StringList();
                          stringList.authorName = listData.getString("author");
                          stringList.headline = listData.getString("title");
                          stringList.publishedTime = listData.getString("publishedAt");
                          stringList.newsDetail = listData.getString("description");
  
                          businessNews.add(stringList);
                      }
  
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
                  return businessNews;
              }
  
              @Override
              protected void onPostExecute(List&lt;StringList&gt; result) {
                  super.onPostExecute(result);
  
                  recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
                  BusinessAdapter adapter = new BusinessAdapter(Business.this, result);
                  recyclerView.setAdapter(adapter);
  
              }
          }
  
          public class BusinessAdapter extends RecyclerView.Adapter&lt;BusinessHolder&gt; {
  
              int prevposition = 0;
              private List&lt;StringList&gt; c;
  
              public BusinessAdapter(Business context, List&lt;StringList&gt; result) {
                  c = context.businessNews;
  
              }
  
              @Override
              public BusinessHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  
                  Context context = parent.getContext();
                  LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                  View view = inflater.inflate(R.layout.layout_news, parent, false);
  
                  return new BusinessHolder(view);
              }
  
              @Override
              public void onBindViewHolder(BusinessHolder holder, int position) {
  
                  StringList m = c.get(position);
                  holder.bindListName(m, position);
  
              @Override
              public int getItemCount() {
                  return c.size();
              }
          }
  
          public class BusinessHolder extends RecyclerView.ViewHolder {
  
              public TextView headlineTextview;
              public TextView authorTextview;
              public TextView timeTextview;
  
              public BusinessHolder(View itemView) {
                  super(itemView);
  
                  headlineTextview = (TextView) itemView.findViewById(R.id.id_headline);
                  authorTextview = (TextView) itemView.findViewById(R.id.id_author);
                  timeTextview = (TextView) itemView.findViewById(R.id.id_time);
  
              }
  
              public void bindListName(final StringList stringList, final int position) {
  
                  headlineTextview.setText(stringList.headline);
                  authorTextview.setText(stringList.authorName);
                  timeTextview.setText(stringList.publishedTime);
  
                  itemView.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
  
                           BusinessDetail s = new BusinessDetail();
                          FragmentTransaction transaction = getFragmentManager().beginTransaction();
                          transaction.replace(R.id.content_frame, s);
                          transaction.addToBackStack(null);
                          transaction.commit();
                      } });}}}}
  </code></pre>
  
  <p>Fragment 2:</p>
  
  <pre><code>public class BusinessDetail extends Fragment {
  
      Bundle bundle;
      private TextView headlineSecond;
      private TextView authorSecond;
      private TextView detailsSecond;
      private List&lt;StringList&gt; s;
  
      public BusinessDetail() {
      }
  
      public void receiveValue(StringList value, int positionValue) {
  
          bundle = new Bundle();
          bundle.putString("news", value.authorName);
        }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View view = inflater.inflate(R.layout.fragment_business_detail, container, false);
  
          headlineSecond = (TextView) view.findViewById(R.id.id_headline_second);
          authorSecond = (TextView) view.findViewById(R.id.id_author_second);
          detailsSecond = (TextView) view.findViewById(R.id.id_details_second);
  
  // I want to set the values received to the textview here
  
          return view;}}
  </code></pre>