title: populate a listview in fragment with a json rereiver php mysql
body: <p>I'm fairly new to fragment but my code seems logical enough to me but still it's either crashing or gives no result at all i don't have an idea what's going wrong with it , im fetshing a json file from a php api , that includes  "annances" advertisements parsing them and listing them in a listview inside of a fragment , 
  here are my fragment class and  adapter</p>
  
  <p>if anyone could refrence a code i can learn from or give a clue where did i went wrong with it , thank you</p>
  
  <pre><code>public class MainFragment extends Fragment{
  
  private String URLstring = "http://192.168.1.38/api/annonce/read.php";
  private static ProgressDialog mProgressDialog;
  private ListView lv;
  ArrayList&lt;DataModel&gt; dataModelArrayList = new ArrayList&lt;DataModel&gt; ();
  private ListAdapter1 listAdapter1;
  
  public static MainFragment newInstance() {
      MainFragment fragment = new MainFragment();
      return fragment;
  }
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  }
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
  
      View v=inflater.inflate(R.layout.main_fragment, container, false);
  
  
      lv  = v.findViewById(R.id.lv);
  
      new JsonTask().execute(URLstring); 
      return v;
  }
  
  private class JsonTask extends AsyncTask&lt;String, String, String&gt; {
      protected void onPreExecute() {
  
      }
  
      protected String doInBackground(String... params) {
          HttpURLConnection connection = null;
          BufferedReader reader = null;
          try {
              URL url = new URL(params[0]);
              connection = (HttpURLConnection) url.openConnection();
              connection.connect();
              InputStream stream = connection.getInputStream();
              reader = new BufferedReader(new InputStreamReader(stream));
              StringBuffer buffer = new StringBuffer();
              String line;
              String file_name="";
              while ((line = reader.readLine()) != null) {
                  try {
                      JSONObject dataobj = new JSONObject(line);
                      DataModel playerModel = new DataModel();
                      playerModel.setPhoto_principale(dataobj.getString("Photo_principale"));
                      playerModel.setTitre_annonce(dataobj.getString("Titre_annonce"));
                      playerModel.setDescription(dataobj.getString("Description"));
                      playerModel.setQuartier(dataobj.getString("Quartier"));
                      dataModelArrayList.add(playerModel);
                  }
                  catch (Exception e){}
                  buffer.append(line + "\n");
              }
              return buffer.toString();
          } catch (MalformedURLException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          } finally {
              if (connection != null) {
                  connection.disconnect();
              }
              try {
                  if (reader != null) {
                      reader.close();
                  }
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return null;
      }
  
  
      @Override
      protected void onPostExecute(String result) {
  
          super.onPostExecute(result);
          setupListview();
  
      }
  
  
  
  }
  
  private void setupListview(){
      removeSimpleProgressDialog();  //will remove progress dialog
      listAdapter1 = new ListAdapter1(getActivity(),dataModelArrayList); // Here we talk about getActivity() because you are using Fragment not 
      //an actual activity so you call it getActivity()
      lv.setAdapter(listAdapter1);
  
  }
  
  public static void removeSimpleProgressDialog() {
      try {
          if (mProgressDialog != null) {
              if (mProgressDialog.isShowing()) {
                  mProgressDialog.dismiss();
                  mProgressDialog = null;
              }
          }
      } catch (IllegalArgumentException ie) {
          ie.printStackTrace();
  
      } catch (RuntimeException re) {
          re.printStackTrace();
      } catch (Exception e) {
          e.printStackTrace();
      }
  
  }
  
  }
  </code></pre>
  
  <p>Here is the Adapter class</p>
  
  <pre><code>public class ListAdapter1 extends BaseAdapter {
  
  private Context context;
  private ArrayList&lt;DataModel&gt; dataModelArrayList;
  public ListAdapter1(Context context, ArrayList&lt;DataModel&gt; dataModelArrayList) {
  
      this.context = context;
      this.dataModelArrayList = dataModelArrayList;
  }
  @Override
  public int getViewTypeCount() {
      return getCount();
  }
  @Override
  public int getItemViewType(int position) {
  
      return position;
  }
  
  @Override
  public int getCount() {
      return dataModelArrayList.size();
  }
  
  @Override
  public Object getItem(int position) {
      return dataModelArrayList.get(position);
  }
  
  @Override
  public long getItemId(int position) {
      return 0;
  }
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent) {
      ViewHolder holder;
  
      if (convertView == null) {
          holder = new ViewHolder();
          LayoutInflater inflater = (LayoutInflater) context
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          convertView = inflater.inflate(R.layout.item_list, null);
  
          holder.photo_principale = (ImageView) convertView.findViewById(R.id.image);
          holder.titre_annonce = (TextView) convertView.findViewById(R.id.titre_annonce);
          holder.description = (TextView) convertView.findViewById(R.id.description);
          holder.quartier = (TextView) convertView.findViewById(R.id.quartier);
  
          convertView.setTag(holder);
      }else {
          // the getTag returns the viewHolder object set as a tag to the view
          holder = (ViewHolder)convertView.getTag();
      }
  
      Picasso.get().load(dataModelArrayList.get(position).getPhoto_principale()).into(holder.photo_principale);
      holder.titre_annonce.setText(dataModelArrayList.get(position).getTitre_annonce());
      holder.description.setText(dataModelArrayList.get(position).getDescription());
      holder.quartier.setText(dataModelArrayList.get(position).getQuartier());
  
      return convertView;
  }
  
  private class ViewHolder {
      // changed protected to public
      public  TextView titre_annonce, description, quartier;
      public ImageView photo_principale;
  }
  </code></pre>