title: Load Images in a List from Database at Server
body: <p>Guys I am not having an appropriate way to load images in the list view of android application. I have to load images in list with there text from the database.
  the database which I am using is MYSQL and PHP Server.</p>
  
  <p>Kindly help me out.</p>
  
  <p>This is my code.</p>
  
  <p>Activity Class:</p>
  
  <pre><code>public class DisplayMagazine extends ListActivity {
  private ProgressDialog pDialog;
  JSONParser jParser = new JSONParser();
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; magazinesList;
  int year;
  private static final String TAG_SUCCESS = "success";
  private static final String TAG_MAGAZINE = "magazines";
  private static final String TAG_MAGAZINE_IMAGE="magazineImage";
  private static final String TAG_MONTH = "month";
  private static final String TAG_PATH = "path";
  JSONArray magazines = null;
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.display_magazine);
      Intent i = getIntent();
      year = i.getIntExtra("year", 0);
      magazinesList = new ArrayList&lt;&gt;();
      new LoadAllMagazines().execute();
      ListView lv = getListView();
       lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                      int position, long id) {
                  TextView textView = (TextView) findViewById(R.id.path);
                      textView.setClickable(true);
                      textView.setMovementMethod(LinkMovementMethod.getInstance());
                      String text = "https://docs.google.com/gview?embedded=true&amp;url="+ textView.getText();
                  textView.setText(Html.fromHtml(text));
              }
          });
      }
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (resultCode == 100) {
          Intent intent = getIntent();
          finish();
          startActivity(intent);
      }
  }
  class LoadAllMagazines extends AsyncTask&lt;String, String, String&gt; {
     @Override
      protected void onPreExecute() {
          super.onPreExecute();
          pDialog = new ProgressDialog(DisplayMagazine.this);
          pDialog.setMessage("Loading Magazines. Please wait...");
          pDialog.setIndeterminate(false);
          pDialog.setCancelable(false);
          pDialog.show();
      }
      protected String doInBackground(String... args) {
          List&lt;NameValuePair&gt; params = new ArrayList&lt;&gt;();
          params.add(new BasicNameValuePair("year", String.valueOf(year)));
          //String url_all_magazines = "http://172.16.26.190/shifaspeaks/get_all_magazines.php";
          String url_all_magazines = "http://10.3.1.117/shifaspeaks/get_all_magazines.php";
          //String url_all_magazines = "http://192.168.1.4/shifaspeaks/get_all_magazines.php";
          JSONObject json = jParser.makeHttpRequest(url_all_magazines, "GET", params);
          Log.d("All Magazines: ", json.toString());
          try {
              int success = json.getInt(TAG_SUCCESS);
              if (success == 1) {
                  magazines = json.getJSONArray(TAG_MAGAZINE);
                      for (int i = 0; i &lt; magazines.length(); i++) {
                      JSONObject c = magazines.getJSONObject(i);
                      String month = c.getString(TAG_MONTH);
                      String path = c.getString(TAG_PATH);
                      //String imageString=c.getString(TAG_MAGAZINE_IMAGE);
                      //byte[] image= Base64.decode(imageString.getBytes(), Base64.DEFAULT);
                      //Bitmap decodedByte= BitmapFactory.decodeByteArray(image,0,image.length);
                      HashMap&lt;String, String&gt; map = new HashMap&lt;&gt;();
                      map.put(TAG_MONTH, month);
                      map.put(TAG_PATH, path);
                      //map.put(TAG_MAGAZINE_IMAGE,decodedByte.toString());
                      magazinesList.add(map);
                  }
              } else {
                  Intent i = new Intent(getApplicationContext(),
                          MainActivity.class);
                  i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                  startActivity(i);
              }
          } catch (JSONException e) {
              e.printStackTrace();
          }
          return null;
      }
      protected void onPostExecute(String file_url) {
          pDialog.dismiss();
          runOnUiThread(new Runnable() {
              public void run() {
                  ListAdapter adapter = new SimpleAdapter(
                          DisplayMagazine.this, magazinesList,
                          R.layout.list_item2, new String[] {TAG_MAGAZINE_IMAGE, TAG_MONTH,
                          TAG_PATH},
                          new int[] {R.id.magazineImage, R.id.month, R.id.path});
                  setListAdapter(adapter);
              }
          });
      }
  }
  </code></pre>
  
  <p>and its XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical" android:layout_width="match_parent"
      android:layout_height="match_parent"&gt;
  
  &lt;ListView
      android:id="@android:id/list"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"/&gt;
  </code></pre>
  
  <p>and its layout for list :</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical" &gt;
  
  
  
  &lt;!-- Product id (pid) - will be HIDDEN - used to pass to other activity --&gt;
  &lt;TextView
      android:id="@+id/month"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      /&gt;
  
  &lt;!-- Name Label --&gt;
  &lt;TextView
      android:id="@+id/path"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:autoLink="web"
      android:clickable="true"
      android:paddingTop="6dip"
      android:paddingLeft="6dip"
      android:textSize="17dip"
      android:textStyle="bold" /&gt;
  </code></pre>
  
  <p>and the PHP Server Script:</p>
  
  <pre><code>&lt;?php
  mysql_connect('127.0.0.1:3306','root','');
  mysql_select_db("shifaspeaks");
  $response = array(); 
  if(isset($_GET["year"])){
  $year = $_GET["year"];
  $result = mysql_query("SELECT month, path, magazineImage FROM magazine where year='$year'") or die(mysql_error());
  if (mysql_num_rows($result) &gt; 0) {
      $response["magazines"] = array();
      while ($row = mysql_fetch_array($result)) {
          $magazine = array();
          $magazine["month"] = $row["month"];
          $magazine["path"] = $row["path"];
          //$magazine["magazineImage"]=$row["magazineImage"];
          array_push($response["magazines"], $magazine);
      }
      $response["success"] = 1;
      echo json_encode($response);
  } else {
      $response["success"] = 0;
      $response["message"] = "No magazines found";
      echo json_encode($response);    
  }
  </code></pre>
  
  <p>Remember I have to load images from database to the list in android with its text. Thank You</p>