title: Deleting item from a Custom ListView
body: <p>I have a Custom ListView which is populated with retrieved from a database. Now, what I can't understand is how to remove an item from the list: searching on Google I've seen different questions without a standard solution, so I have doubts about this. How can I delete a row from a CustomListView also using Async Task?</p>
  
  <p>Here is Leggi_Pizzaiolo activity (where I display the listView):</p>
  
  <pre><code>public class Leggi_Pizzaiolo extends Activity
  {
      // Progress Dialog
      private ProgressDialog pDialog;
      public List list = new LinkedList();
      // Creating JSON Parser object
      JSONParser jParser = new JSONParser();
  
      ArrayList&lt;HashMap&lt;String, String&gt;&gt; productsList;
  
      // url to get all products list
      private static String url_all_products = "http://10.0.2.2/tesina/Leggi_Pizzaiolo.php";
  
      // JSON Node names
      private static final String TAG_SUCCESS = "Esito";
      private static final String TAG_PRODUCTS = "comande";
      private static final String TAG_PID = "ID";
      private static final String TAG_NAME = "Nome";
      private static final String TAG_TABLE = "Tavolo";
      public ListView lv;
      // products JSONArray
      JSONArray products = null;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.ordini_cuoco);
  
          // Hashmap for ListView
          productsList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  
          // Loading products in Background Thread
  
          // Get listview
          lv = (ListView)findViewById(R.id.lista);
  
          new LoadAllProducts().execute();
  
      }
  
      /**
       * Background Async Task to Load all product by making HTTP Request
       * */
      class LoadAllProducts extends AsyncTask&lt;String, String, String&gt; 
      {
  
          /**
           * Before starting background thread Show Progress Dialog
           * */
          @Override
          protected void onPreExecute() {
              super.onPreExecute();
              pDialog = new ProgressDialog(Leggi_Pizzaiolo.this);
              pDialog.setMessage("Loading products. Please wait...");
              pDialog.setIndeterminate(false);
              pDialog.setCancelable(false);
              pDialog.show();
          }
  
          /**
           * getting All products from url
           * */
          protected String doInBackground(String... args) {
              // Building Parameters
              List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
              // getting JSON string from URL
              JSONObject json = jParser.makeHttpRequest(url_all_products, "GET", params);
  
              // Check your log cat for JSON reponse
              Log.d("All Products: ", json.toString());
  
              try {
                  // Checking for SUCCESS TAG
                  int success = json.getInt(TAG_SUCCESS);
  
                  if (success == 1) {
                      // products found
                      // Getting Array of Products
                      products = json.getJSONArray(TAG_PRODUCTS);
  
                      // looping through All Products
                      for (int i = 0; i &lt; products.length(); i++) {
                          JSONObject c = products.getJSONObject(i);
  
                          // Storing each json item in variable
                          int id = c.getInt(TAG_PID);
                          String name = c.getString(TAG_NAME);
                          int Tavolo= c.getInt(TAG_TABLE);
  
                          list.add(new Comanda(name, id, Tavolo));
  
                      }
                  } else {
                      // no products found
                      // Launch Add New product Activity
                      Intent i = new Intent(getApplicationContext(),
                              Listino.class);
                      // Closing all previous activities
                      i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                      startActivity(i);
                  }
              } catch (JSONException e) {
                  e.printStackTrace();
              }
  
              return null;
          }
  
          /**
           * After completing background task Dismiss the progress dialog
           * **/
          protected void onPostExecute(String file_url) 
          {
              // dismiss the dialog after getting all products
              pDialog.dismiss();
              // updating listview
              final ComandaCursorAdapter adapter = new ComandaCursorAdapter(Leggi_Pizzaiolo.this, R.layout.comanda_cuoco, list);
              lv.setAdapter(adapter);
  
  
          }
  
  
  
      }
  
  
  } 
  </code></pre>
  
  <p>This is the CursorAdapter:</p>
  
  <pre><code>public class ComandaCursorAdapter extends ArrayAdapter&lt;Comanda&gt;
  {
  
  public ComandaCursorAdapter(Context context, int comandaCuoco, List list) {
      super(context, comandaCuoco, list);
      // TODO Auto-generated constructor stub
  }
  
  
  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
      LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      convertView = inflater.inflate(R.layout.comanda_cuoco, null);
  
      TextView Nome = (TextView)convertView.findViewById(R.id.Comanda);
      TextView Tavolo = (TextView)convertView.findViewById(R.id.Tavolo);
      TextView Codice = (TextView)convertView.findViewById(R.id.Codice);
  
      Comanda c = getItem(position);
  
      Nome.setText(c.getNome());
      Tavolo.setText("Tavolo: " + Integer.toString(c.getTavolo()));
      Codice.setText("Codice: " + Integer.toString(c.getCodice()));
  
  
      return convertView;
  
  }
  </code></pre>
  
  <p>And this is the object Comanda:</p>
  
  <pre><code>public class Comanda {
  
      private String Nome;
      private int Codice;
      private int Tavolo;
  
      public Comanda(String Nome, int Codice, int Tavolo)
      {
          this.Nome = Nome;
          this.Codice = Codice;
          this.Tavolo = Tavolo;
  
      }
  
      public String getNome()
      {
          return Nome;
      }
  
      public void setNome(String Nome)
      {
          this.Nome = Nome;
      }
  
      public int getCodice()
      {
          return Codice;
      }
  
      public void setCodice(int Codice)
      {
          this.Codice = Codice;
      }
  
      public int getTavolo()
      {
          return Tavolo;
      }
  
      public void setTavolo(int Tavolo)
      {
          this.Tavolo = Tavolo;
      }
  
  
  }
  </code></pre>
  
  <p>Now, where I have to declare the setOnItemClickListener in Leggi_Pizzaiolo activity? Should I have to implement a remove method into the class or something? Please let me know how...</p>