title: How to delete listview items using a button on the list view items
body: <p>I want to be able to remove a list item from a ListView by clicking a button that is on the ListView.</p>
  
  <p>So I thought the right path to head down would be to set the OnClickListener for the buttons. The problem is, I don't know how to actually remove the language from AddSpeakerActivity.languages as well as remove the associated item from the ListView. How can I do this? Thanks!</p>
  
  <p>Here is my layout for the list items:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;                                          
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"           
          android:layout_width="fill_parent"                                      
          android:layout_height="fill_parent"                                     
          android:orientation="horizontal" android:baselineAligned="false" &gt;      
      &lt;TextView android:textAppearance="?android:attr/textAppearanceMedium"          
              android:layout_height="wrap_content"                                
              android:text=""                                                     
              android:layout_width="0dp"                                          
              android:layout_weight="1"                                           
              android:layout_gravity="center_vertical"                            
              android:id="@+id/recordingName"/&gt;                                   
      &lt;ImageButton android:src="@drawable/cancel_32"                              
              android:layout_gravity="center"                                     
              android:padding="5dip"                                              
              android:layout_margin="10dip"                                       
              android:scaleType="centerInside"                                    
              android:layout_width="60dip"                                        
              android:layout_height="60dip"                                       
              android:id="@+id/removeButton"/&gt;                                    
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Here is the activity in question:</p>
  
  <pre><code>package org.lp20.aikuma.ui;                                                     
  
  import android.app.ListActivity;                                                
  import android.content.Intent;                                                  
  import android.os.Bundle;                                                       
  import android.util.Log;                                                        
  import android.view.View;                                                       
  import android.widget.ArrayAdapter;                                             
  import java.io.IOException;                                                     
  import java.util.ArrayList;                                                     
  import java.util.List;                                                          
  import org.lp20.aikuma.model.Language;                                          
  import org.lp20.aikuma.model.Recording;                                         
  import org.lp20.aikuma.R;                                                       
  import org.lp20.aikuma.util.FileIO;                                             
  
  public class AddSpeakerActivity extends ListActivity {                          
  
      @Override                                                                   
      public void onCreate(Bundle savedInstanceState) {                           
          super.onCreate(savedInstanceState);                                     
          setContentView(R.layout.add_speaker);                                   
          languages = FileIO.readDefaultLanguages();                              
      }                                                                           
  
      @Override                                                                   
      public void onResume() {                                                    
          super.onResume();                                                       
  
          ArrayAdapter&lt;Language&gt; adapter =                                        
                  new SpeakerLanguagesArrayAdapter(this, languages);              
          setListAdapter(adapter);                                                
      }                                                                           
  
      public void onAddLanguageButton(View view) {                                
          Intent intent = new Intent(this, LanguageFilterList.class);             
          startActivityForResult(intent, SELECT_LANGUAGE);                        
      }                                                                           
  
      protected void onActivityResult(int requestCode, int resultCode, Intent     
              intent) {                                                           
          if (requestCode == SELECT_LANGUAGE) {                                   
              if (resultCode == RESULT_OK) {                                      
                  languages.add((Language)                                        
                          intent.getParcelableExtra("language"));                 
                  Log.i("langs", "langs");                                        
              }                                                                   
          }                                                                       
      }                                                                           
  
      static final int SELECT_LANGUAGE = 0;                                       
      private List&lt;Language&gt; languages = new ArrayList&lt;Language&gt;();               
  }
  </code></pre>
  
  <p>Here is the array adapter:</p>
  
  <pre><code>package org.lp20.aikuma.ui;                                                     
  
  import android.content.Context;                                                 
  import android.util.Log;                                                        
  import android.view.LayoutInflater;                                             
  import android.view.View;                                                       
  import android.view.View.OnClickListener;                                       
  import android.view.ViewGroup;                                                  
  import android.widget.ArrayAdapter;                                             
  import android.widget.ImageButton;                                              
  import android.widget.TextView;                                                 
  import java.util.List;                                                          
  import org.lp20.aikuma.model.Language;                                          
  import org.lp20.aikuma.R;                                                       
  
  public class SpeakerLanguagesArrayAdapter extends ArrayAdapter&lt;Language&gt; {         
      public SpeakerLanguagesArrayAdapter(Context context, List&lt;Language&gt;         
              languages) {                                                        
          super(context, listItemLayout, languages);                              
          inflater = (LayoutInflater)                                             
                  context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);         
      }                                                                           
  
      @Override                                                                   
      public View getView(int position, View _, ViewGroup parent) {               
          Log.i("langs", "getView");                                              
          View recordingView =                                                    
                  (View) inflater.inflate(listItemLayout, parent, false);         
          final Language language = getItem(position);                            
          TextView recordingNameView =                                            
                  (TextView) recordingView.findViewById(R.id.recordingName);         
          ImageButton removeLanguageButton =                                      
                  (ImageButton) recordingView.findViewById(R.id.removeButton);    
          removeLanguageButton.setOnClickListener(new OnClickListener() {         
              public void onClick(View view) {                                    
                  Log.i("langs", "language: " + language);                        
              }                                                                   
          });                                                                     
  
          recordingNameView.setText(language.toString());                         
          return recordingView;                                                   
      }                                                                           
  
      private static final int listItemLayout =                                   
              R.layout.speakerlanguages_list_item;                                
      private LayoutInflater inflater;                                            
  
  }
  </code></pre>