Updating a listview from a HTTP request
<p>I am trying to display a list of items I am getting from a mysql database on a webserver. Here is my create for the page.</p>

<pre><code>  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.getlist);
    showBusyDialog();
    new GetData()
    .execute(picdetails);
}
</code></pre>

<p>Here is my GetData class. The problem here is with the lines that are adding items to the listview. I am passing a JSON array as a text result.</p>

<pre><code>   public class GetData extends AsyncTask&lt;String, Void, String&gt; {
      @Override
        protected String doInBackground(String... pic) {
            // You might be tempted to display the busy dialog here, but you
            // CAN'T update the UI from this method!
            return loadImageFromNetwork(pic[0]);
        }

        @Override
        protected void onPostExecute(String result) {
            // Our long-running process is done, and we can safely access the UI thread
            int ct_id;
            String item_make;
            String item_model;
            String item_price;
            String item_desc;
            String item_location;
            String item_image;
            dismissBusyDialog();

            TableLayout tl = (TableLayout)findViewById(R.id.myTableLayout1);
            try{
                 JSONArray jArray = new JSONArray(result);
                 JSONObject json_data=null;
                 for(int i=0;i&lt;jArray.length();i++){
                     json_data = jArray.getJSONObject(i);
                        ct_id=json_data.getInt("id");
                        item_make=json_data.getString("make");
                        item_model=json_data.getString("model");
                        item_price = json_data.getString("price");
                        item_desc = json_data.getString("cardesc");
                        item_location = json_data.getString("location");
                        item_image = json_data.getString("image");
                        String image_URL = "http://www.myurl.com/images/" + car_image;

                     TableRow tr = new TableRow(null);
                     tr.setId(ct_id);
                     tr.setClickable(true);

                     tr.setOnClickListener(new  OnClickListener() {

                            @Override
                            public void onClick(final View v) {

                                String sdet_id;
                                int det_id;
                    //          v.setBackgroundColor(Color.GRAY);
                                det_id = v.getId();
                                sdet_id = String.valueOf(det_id);
                                final Intent i = new Intent();
                                i.setClassName("demo.example.com", "demo.example.com.viewdetails");
                                i.putExtra("Det_id", sdet_id);
                                startActivity(i);

                      //        v.setBackgroundColor(Color.TRANSPARENT);
                                // TODO Auto-generated method stub
                            }
                        });
                     TableLayout.LayoutParams tableRowParams=
                          new TableLayout.LayoutParams
                          (TableLayout.LayoutParams.FILL_PARENT,TableLayout.LayoutParams.WRAP_CONTENT);

                        int leftMargin=20;
                        int topMargin=10;
                        int rightMargin=15;
                        int bottomMargin=20;

                        tableRowParams.setMargins(leftMargin, topMargin, rightMargin, bottomMargin);

                        tr.setLayoutParams(tableRowParams);

                          /* Create a Button to be the row-content. */
                     ImageView myimage = new ImageView(R.layout.getlist);

                     BitmapFactory.Options bmOptions;
                    bmOptions = new BitmapFactory.Options();
                    bmOptions.inSampleSize = 1;
                    Bitmap bm = LoadImage(image_URL, bmOptions);
                    myimage.setImageBitmap(bm);
                     tr.addView(myimage);
                     TextView tmake=new TextView(R.layout.getlist);
                    // tmake.setText(item_make);
                     tmake.setText(Html.fromHtml("&lt;H1&gt;" + "&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;" + item_location + "&lt;/H1&gt;" +  "&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;;" + item_desc  
                  ));
                     tr.addView(tmake); 

                     TextView tmodel=new TextView(R.layout.getlist);
                     tmodel.setText(Html.fromHtml("&lt;b&gt;&lt;H1&gt;" + "&amp;nbsp;&amp;nbsp;" + "€" + item_price + "&lt;/b&gt;&lt;/H1&gt;&lt;/br&gt;&lt;/br&gt;" ));
                     tr.addView(tmodel);



                /* Add row to TableLayout. */
                 //  tr.setPadding(50, 0, 0, 0);
                     tl.addView(tr);
                     View v = new View(R.layout.getlist);
                     v.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.FILL_PARENT, 1));
                     v.setBackgroundColor(Color.rgb(51, 51, 51));
                     tl.addView(v);
                      }

                 }

                 catch(JSONException e1){
                  Toast.makeText(getBaseContext(), "No Category Found" ,Toast.LENGTH_LONG).show();
                 } catch (ParseException e1) {
                    e1.printStackTrace();
            }



        }
    }
</code></pre>

<p>The problem appears to be with creating new items to add to the view, lines like this</p>

<pre><code>   View v = new View(R.layout.getlist);
</code></pre>

<p>Is my overall structure ok or do I need to do this another way?</p>
