title: Customizing Android ListView Items with Custom ArrayAdapter how remove item
body: <p>with few examples i have build this application, I would like to remove the item when I click on the imagebutton( declared on the row item xml)
  I have tried to implement the callback invoked when the imagebuttom are pressed, but after how can delete/remove the item?
  How can do that?
  thx for all!</p>
  
  <p>This is my activity:</p>
  
  <pre><code>public class MainActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
  
  
          Ordine ordine_data[] = new Ordine[]
                  {
                      new Ordine("Cloudy1"),
                      new Ordine("Cloudy2"),
                      new Ordine("Cloudy3"),
                      new Ordine("Cloudy4"),
                      new Ordine("Cloudy5")
                  };
  
          final ArrayList&lt;Ordine&gt; list = new ArrayList&lt;Ordine&gt;();
          for (int i = 0; i &lt; ordine_data.length; ++i) {
            list.add(ordine_data[i]);
          }
          final OrdineAdapter adapter = new OrdineAdapter(this,R.layout.order_list_row, ordine_data);
           ListView listview = (ListView) findViewById(R.id.listview);
  
          View header = (View)getLayoutInflater().inflate(R.layout.listview_header, null);
          listview.addHeaderView(header);        
          listview.setAdapter(adapter);
  
  
          //final StableArrayAdapter adapter = new StableArrayAdapter(this,android.R.layout.simple_list_item_1, list);
          //listview.setAdapter(adapter);
  
          listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
            @Override
            public void onItemClick(AdapterView&lt;?&gt; parent, final View view, int position, long id) {
  
              final String item = (String) parent.getItemAtPosition(position);
              view.animate().setDuration(1000).alpha(0)
                  .withEndAction(new Runnable() {
                    @Override
                    public void run() {
                      list.remove(item);
                      adapter.notifyDataSetChanged();
                      view.setAlpha(1);
                    }
                  });
            }
  
          });
      }
  
  
  
  
      private class StableArrayAdapter extends ArrayAdapter&lt;String&gt; {
  
          HashMap&lt;String, Integer&gt; mIdMap = new HashMap&lt;String, Integer&gt;();
  
          public StableArrayAdapter(Context context, int textViewResourceId,
              List&lt;String&gt; objects) {
            super(context, textViewResourceId, objects);
            for (int i = 0; i &lt; objects.size(); ++i) {
              mIdMap.put(objects.get(i), i);
            }
          }
  
          @Override
          public long getItemId(int position) {
            String item = getItem(position);
            return mIdMap.get(item);
          }
  
          @Override
          public boolean hasStableIds() {
            return true;
          }
  
        }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  
  }
  </code></pre>
  
  <p>this is my adapter:</p>
  
  <pre><code>public class OrdineAdapter extends ArrayAdapter&lt;Ordine&gt;{
  
      Context context; 
      int layoutResourceId;    
      Ordine data[] = null;
  
      public OrdineAdapter(Context context, int layoutResourceId, Ordine[] data) {
          super(context, layoutResourceId, data);
          this.layoutResourceId = layoutResourceId;
          this.context = context;
          this.data = data;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          View row = convertView;
          OrdineHolder holder = null;
  
          if(row == null)
          {
              LayoutInflater inflater = ((Activity)context).getLayoutInflater();
              row = inflater.inflate(layoutResourceId, parent, false);
  
              holder = new OrdineHolder();
  
              holder.txtTitle = (TextView)row.findViewById(R.id.txtUserName);        
              row.setTag(holder);
  
              ImageButton btnRemove = (ImageButton)row.findViewById(R.id.remove_product);
              btnRemove.setOnClickListener(new OnClickListener(){
  
                  @Override
                  public void onClick(View arg0) {
                      // TODO Auto-generated method stub
                      int i;
                      i=0; //this is for testing only!!!
  
                  }
  
              });
          }
          else
          {
              holder = (OrdineHolder)row.getTag();
          }
  
          Ordine ordine = data[position];
          holder.txtTitle.setText(ordine.title);
  
  
          return row;
      }
  
      static class OrdineHolder
      {
  
          TextView txtTitle;
      }
  }
  </code></pre>