title: Custom List view with Fragments
body: <p>I am working on custom list view which access inbox messages it is working fine with simple main activity project. But as i am trying 
  with "fragments" activity its not working.Can Anyone help me.</p>
  
  <pre><code>public class tab2 extends Fragment {
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_tab2, container, false);
          ListView listView = view.findViewById(R.id.messageList);   
          return view;    
      }
  
      @Override
      public void onCreate(Bundle savedInstanceState){
          super.onCreate(savedInstanceState);    
          List&lt;smsdata&gt; smsList = new ArrayList&lt;&gt;();    
          Uri uri = Uri.parse("content://sms/inbox");
          Cursor c;    
          assert getContentResolver() != null;
          c=getContentResolver().query(uri,null,null,null,null);
          assert c != null;
          if (c.moveToFirst()) {
              if (c.moveToFirst()) {
                  for (int i = 0; i &lt; c.getCount(); i++) {
                      smsdata sms = new smsdata();
                      sms.setBody(c.getString(c.getColumnIndexOrThrow("body")));
                      sms.setNumber(c.getString(c.getColumnIndexOrThrow("address")));
                      smsList.add(sms);
  
                      c.moveToNext();
                  }
  
              }
              c.moveToNext();
          }
          c.close();    
      }
      private ContentResolver getContentResolver() {
          return null;
      }    
  }
  </code></pre>
  
  <p>Below is the list adapter class it is working in both type of activities.But i don't know how to set adapter</p>
  
  <pre><code> public class listadapter extends ArrayAdapter&lt;smsdata&gt; {
      TextView text;
      TextView text2;
      private Context context;
      private List&lt;smsdata&gt;smsList;
      public listadapter(Context context,List&lt;smsdata&gt;smsList){
          super(context,R.layout.fragment_tab2,smsList);
          this.context=context;
          this.smsList=smsList;
  
      }
      @Override
      public View getView(int position,View convertView,ViewGroup parent){
          LayoutInflater inflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          @SuppressLint("ViewHolder") View rowView = inflater.inflate(R.layout.fragment_tab2,parent,false);
  
          text = rowView.findViewById(R.id.smsNumberText);
          text.setText(smsList.get(position).getNumber());
  
          text2 = rowView.findViewById(R.id.smsDetail);
          text2.setText(smsList.get(position).getBody());
          return rowView;
  
  
      }
  
  }
  </code></pre>