title: how to send JSON post data to server by using ItemClickListener
body: <p>I'm doing a project about JSON  receive and send post data. I succeed receiving data using listView but i don't know how to send the "name" to the server. 
  Here's my code:</p>
  
  <pre><code>import java.util.ArrayList;
  import java.util.HashMap;
  
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.app.ProgressDialog;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.view.View;
  import android.widget.AdapterView;
  import android.widget.Button;
  import android.widget.ListAdapter;
  import android.widget.ListView;
  import android.widget.SimpleAdapter;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import learn2crack.asynctask.library.JSONParser;
  
  public class MainActivity extends Activity {
      ListView list;
      TextView ver;
      TextView name;
      TextView api;
      Button Btngetdata;
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; oslist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
      //URL to get JSON Array
      private static String url = "http://api.learn2crack.com/android/jsonos/";
      private static String purl = ""; // the server hasn't ready yet 
  
      //JSON Node Names 
      private static final String TAG_OS = "android";
      private static final String TAG_VER = "ver";
      private static final String TAG_NAME = "name";
      private static final String TAG_API = "api";
  
      JSONArray android = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.activity_main);
          oslist = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          Btngetdata = (Button)findViewById(R.id.getdata);
          Btngetdata.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View view) {
                   new JSONParse().execute();
  
              }
          });
  
      }
  
      private class JSONParse extends AsyncTask&lt;String, String, JSONObject&gt; {
           private ProgressDialog pDialog;
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
               ver = (TextView)findViewById(R.id.vers);
               name = (TextView)findViewById(R.id.name);
               api = (TextView)findViewById(R.id.api);
              pDialog = new ProgressDialog(MainActivity.this);
              pDialog.setMessage("Getting Data ...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(true);
              pDialog.show();
  
          }
  
          @Override
          protected JSONObject doInBackground(String... args) {
  
              JSONParser jParser = new JSONParser();
  
              // Getting JSON from URL
              JSONObject json = jParser.getJSONFromUrl(url);
              return json;
          }
           @Override
           protected void onPostExecute(JSONObject json) {
               pDialog.dismiss();
               try {
                      // Getting JSON Array from URL
                      android = json.getJSONArray(TAG_OS);
                      for(int i = 0; i &lt; android.length(); i++){
                      JSONObject c = android.getJSONObject(i);
  
                      // Storing  JSON item in a Variable
                      String ver = c.getString(TAG_VER);
                      String name = c.getString(TAG_NAME);
                      String api = c.getString(TAG_API);
  
                      // Adding value HashMap key =&gt; value
  
                      HashMap&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
  
                      map.put(TAG_VER, ver);
                      map.put(TAG_NAME, name);
                      map.put(TAG_API, api);
  
                      oslist.add(map);
                      list=(ListView)findViewById(R.id.list);
  
                      ListAdapter adapter = new SimpleAdapter(MainActivity.this, oslist,
                              R.layout.list_item,
                              new String[] { TAG_VER,TAG_NAME, TAG_API }, new int[] {
                                      R.id.vers,R.id.name, R.id.api});
  
                      list.setAdapter(adapter);
  
                      list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
                          @Override
                          public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                                  int position, long id) {
                              Toast.makeText(MainActivity.this, "You Clicked at "+oslist.get(+position).get("name"), Toast.LENGTH_SHORT).show();
                              //send "name" to the (purl)
  
  
                          }
                      });
  
  
                      }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
           }
      }
  
  }      
  </code></pre>
  
  <p>If can. I also wish to limit the ItemClickListener not more than 3 times, something like this :</p>
  
  <pre><code>while (list.setOnItemClickListener&lt;3){
  } 
  </code></pre>
  
  <p>i tried this method 
  list.setOnItemClickListener(new AdapterView.OnItemClickListener() {</p>
  
  <pre><code>                    @Override
                      public void onItemClick(AdapterView&lt;?&gt; parent, View view,
                                              int position, long id) {
                          Toast.makeText(MainActivity.this, "You Clicked at "+oslist.get(+position).get("name"), Toast.LENGTH_SHORT).show();
  
                          //testing 1 start
                          //the year data to send
                          ArrayList&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;();
                          String sname = oslist.get(+position).get("name");
                          nameValuePairs.add(new BasicNameValuePair("name",sname));
  
                          //http post
                          try{
                                  HttpClient httpclient = new DefaultHttpClient();
                                  HttpPost httppost = new HttpPost(purl);
                                  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());
                          }
  
                          //testing end
  
                      }
                  });
  </code></pre>
  
  <p>because of my partner's server hasn't ready i cant test this can really work or not. 
  Please help me with this problem and thanks for very one work answered my question.</p>