how to update a listview in thread?
<p>i want to get some information from the remote server and display that data in listview, i have retrieved the data from the server, but i don't know how to display that in the list view,
here is my code, in this code i have displayed a listview with static data and tried to update this list view by the data obtaining from the server, </p>

<p>i don't know where to update the list view, please anyone help me to do this</p>

<pre><code>package com.listview;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.app.ListActivity;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class ListViewActivity extends ListActivity {
/** Called when the activity is first created. */
private ThreadTest mThreadTest;
ArrayList&lt;String &gt; arlist;
public void onCreate(Bundle savedInstanceState) {


      super.onCreate(savedInstanceState);
      mThreadTest=new ThreadTest();       
      Thread tt=new Thread(mThreadTest);
      tt.start();   
//create a static arraylist to display it in listview
      arlist = new ArrayList&lt;String&gt;();
      arlist.add("xxxxxxxxxxxx");
      arlist.add("yyyyyyyyyyyy");
      ArrayAdapter&lt;String&gt;  arrayAdapter = new ArrayAdapter&lt;String&gt;(this,R.layout.list_item, arlist);
      setListAdapter(arrayAdapter);       
//create listview

      ListView lv = getListView();
      lv.setTextFilterEnabled(true);
      lv.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView&lt;?&gt; parent, View view,
            int position, long id) {
// When clicked, show a toast with the TextView text

          Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
              Toast.LENGTH_SHORT).show();
        }
      });
    }

static public class ThreadTest implements Runnable
{
    ListViewActivity li=new ListViewActivity();             
    JSONArray jArray;
    String result = null;
    InputStream is = null;
    StringBuilder sb=null;
    public  ArrayList al,arraylist;
    public void run() 
    {
//get some details from remote server as json string 

        ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
        try
        {

            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://xxxxxxxxx/clients/yyyyyy/city.php");
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            HttpEntity entity = response.getEntity();
            is = entity.getContent();
         }
        catch(Exception e)
        {
            Log.e("log_tag", "Error in http connection "+e.toString());
        }
        try{                
            BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
            sb = new StringBuilder();
            sb.append(reader.readLine() + "\n");
            String line="0";
            while ((line = reader.readLine()) != null) 
            {
                    sb.append(line  );
            }
            is.close();
            result=sb.toString();

/**************************************
             * result is [{"city_id":"1","city_name":"madurai"},{"city_id":"2","city_name":"coimbatore"},{"city_id":"3","city_name":"chennai"}]
             */

//parse the json string values

            JSONArray array = new JSONArray(result);
            for (int i = 0; i &lt; array.length(); i++) 
            {
                JSONObject row = array.getJSONObject(i);
                int id = row.getInt("city_id");                 
                String name = row.getString("city_name");
//add the cityname to arraylist to display it in listview after the thread exeucted
                arraylist.add(name);                                                    
            }            

        }
        catch(Exception e)
        {
              Log.e("log_tag", "Error converting result "+e.toString());
        }
    }
}
</code></pre>

<p>}</p>

<p>I have found a good tutorial at <a href="http://www.sitepoint.com/loading-twitter-data-into-android-with-lists/" rel="nofollow">http://www.sitepoint.com/loading-twitter-data-into-android-with-lists/</a> to do this,</p>
