title: How to call another fragment from base adapter class in android
body: <p>I am having the list view populated with custom adapter. Now i want to go to the another fragment on button clicking present inside the list item.But i am getting error called  </p>
  
  <pre><code>java.lang.IllegalArgumentException: No view found for id 0x7f0d0098 (android.lotus.com.androidmis:id/containerView) for fragment Chat_support_fragment{22168830 #2 id=0x7f0d0098}
                                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1059)
                                                                                    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1248)
                                                                                    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:738)
                                                                                    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1613)
                                                                                    at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:517)
                                                                                    at android.os.Handler.handleCallback(Handler.java:733)
                                                                                    at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                                    at android.os.Looper.loop(Looper.java:149)
                                                                                    at android.app.ActivityThread.main(ActivityThread.java:5061)
                                                                                    at java.lang.reflect.Method.invokeNative(Native Method)
                                                                                    at java.lang.reflect.Method.invoke(Method.java:515)
                                                                                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
                                                                                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:603)
                                                                                    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Can any one tell me how to achieve this and this is my base adapter code </p>
  
  <pre><code>import java.util.List;
  import java.util.Objects;
  
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.graphics.Color;
  import android.lotus.com.androidmis.Chat_support_fragment;
  import android.lotus.com.androidmis.R;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.util.Log;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.lotus.mis.modle.Complaints.Complaint;
  import com.lotus.mis.modle.MyAppApplication;
  import com.subtabs.complaints.Complaints_history;
  import com.subtabs.complaints.Complaints_pending;
  
  import org.ksoap2.SoapEnvelope;
  import org.ksoap2.serialization.SoapObject;
  import org.ksoap2.serialization.SoapSerializationEnvelope;
  import org.ksoap2.transport.HttpTransportSE;
  import org.w3c.dom.Text;
  
  
  public class Chat_history_Adapter extends BaseAdapter {
  
      Context context;
      public List&lt;Complaint&gt; objects;
      ProgressDialog progressdialog;
      String UserID;
      MyAppApplication mApp;
      public Boolean flag_bit=false;
      public int pos;
      FragmentManager fm;
  
      public Chat_history_Adapter(Context context,int resource,List&lt;Complaint&gt; objects,FragmentManager fm)
      {
          this.context = context;
          this.objects = objects;
          this.fm = fm;
      }
  
      @Override
      public int getCount() {
          // TODO Auto-generated method stub
  
          return  objects.size();
      }
  
      @Override
      public Object getItem(int position) {
          // TODO Auto-generated method stub
          return objects.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return position;
      }
  
      @Override
      public View getView(final int position, View convertView, ViewGroup parent) {
          // TODO Auto-generated method stub
  
          //  View POItemRow = inflater.inflate(R.layout.activity_poitem_listrow,parent,false);
  
          View PurchaseOrderRow = LayoutInflater.from(context).inflate(R.layout.layout_chat_history_adapter,null);
          pos = position;
          progressdialog = new ProgressDialog(context);
  
          mApp  = ((MyAppApplication)context.getApplicationContext());
          final Complaint TR = (Complaint)objects.get(position);
  
          final String RequestNO = TR.getTicketNo();
          final String reqID = TR.getComplaintID();
  
          Complaint Complaintlist = (Complaint) objects.get(position);
  
          //TextView txt_PONo = (TextView) PurchaseOrderRow.findViewById(R.id.txt_PONo);
          //TextView txt_SuppName = (TextView) PurchaseOrderRow.findViewById(R.id.txt_SuppName);
          TextView username = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_empname);
          username.setText(mApp.getmGlobal_UserName());
          TextView userid = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_userid);
          userid.setText(mApp.getmGlobal_UserID());
          TextView module_name  = (TextView)PurchaseOrderRow.findViewById(R.id.txt_module_name);
          module_name.setText(Complaintlist.getText2());
          TextView Ref_no = (TextView)PurchaseOrderRow.findViewById(R.id.txt_ref_no);
          Ref_no.setText(Complaintlist.getTicketNo());
          TextView created_by = (TextView)PurchaseOrderRow.findViewById(R.id.txt_created_by_complaint);
          created_by.setText(Complaintlist.getCreatedBy());
          TextView created_Date= (TextView)PurchaseOrderRow.findViewById(R.id.txt_created_date_complaint);
          created_Date.setText(Complaintlist.getCreatedDate());
          TextView complaint_sub = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_sub);
          complaint_sub.setText(Complaintlist.getComplaintName());
          TextView complaint_body = (TextView)PurchaseOrderRow.findViewById(R.id.txt_complaint_body);
          complaint_body.setText(Complaintlist.getText1());
          final Button chat_support = (Button)PurchaseOrderRow.findViewById(R.id.btn_chat_support);
          chat_support.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
  
  
                  //calling another fragment from adapter class
  
  
                  Chat_support_fragment chat_support_fragment = new Chat_support_fragment();
                  FragmentTransaction sales_xfragmentTransaction = fm.beginTransaction();
                  sales_xfragmentTransaction.replace(R.id.containerView, chat_support_fragment).commit(); //error occurring
  
  
  
                  Toast.makeText(context,"Chat support",Toast.LENGTH_SHORT).show();
  
  
              }
          });
  </code></pre>
  
  <p>This is my Called activity:</p>
  
  <pre><code>import android.content.Context;
  import android.net.Uri;
  import android.os.Bundle;
  import android.support.annotation.Nullable;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  
  
  public class Chat_support_fragment extends Fragment {
  
      View Root_view;
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  
          Root_view = inflater.inflate(R.layout.layout_chat_support_fragment,container,false);
  
          return Root_view;
      }
  }
  </code></pre>
  
  <p>This is my fragment_layout:</p>
  
  <pre><code>&lt;FrameLayout 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"
      tools:context="android.lotus.com.androidmis.Chat_support_fragment"&gt;
  
      &lt;FrameLayout
          android:id="@+id/containerView"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
  
      &lt;/FrameLayout&gt;
  
  
  &lt;/FrameLayout&gt;
  </code></pre>