Want to remove the selected item from Listview
<p>I have used a List and an Arrayadapter to put strings in a Listview.  Now I want to remove the selected Item.  I have tried the following code, but it's not working well. How can I fix this?</p>

<p>Here's my code:</p>

<pre><code>TextView t1;
String[] temp;
mylist = (ListView) findViewById(R.id.list);
final List&lt;String&gt; wordList = Arrays.asList(temp);
adapter = new ArrayAdapter&lt;String&gt;(this,
                                   android.R.layout.simple_list_item_multiple_choice, 
                                   wordList);
delete.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View arg0) {
       int index = mylist.getSelectedItemPosition();
       int count=mylist.getCount();
       for(int i=0;i&lt;=count;i++) {
           if (index &gt;= 0) {
               t1.setText(wordList.remove(index));
           }
           adapter.notifyDataSetChanged();
       } 
   }
});
</code></pre>

<p>Here's more source code:</p>

<pre><code>    public class Edit extends Activity {
        SharedPreferences sharedpref;
        ListView mylist;
        String[] temp;
        String name, 
        ArrayAdapter&lt;String&gt; adapter;
        Button save, delete, cancel;
        TextView t1;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            setContentView(R.layout.edit);
            mylist = (ListView) findViewById(R.id.list);
            cancel = (Button) findViewById(R.id.cancel1);
            save = (Button) findViewById(R.id.save1);
            delete = (Button) findViewById(R.id.delete1);
            t1=(TextView)findViewById(R.id.textView1);
            sharedpref = PreferenceManager
                    .getDefaultSharedPreferences(getApplicationContext());
            name = sharedpref.getString("Visible_selected", "");

            String delimiter = "\n";
            temp = name.split(delimiter);

            mylist.setItemsCanFocus(true);
            mylist.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
             final List&lt;String&gt; wordList = Arrays.asList(temp);  

            adapter = new ArrayAdapter&lt;String&gt;(this,
                    android.R.layout.simple_list_item_multiple_choice, wordList);
            mylist.setAdapter(adapter);
            save.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    // TODO Auto-generated method stub

                }
            });

            delete.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View arg0) {
                    mylist.setOnItemClickListener(new OnItemClickListener() {
                        private String getSelectedItemOfList;
                        @Override
                        public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1,
                                int arg2, long arg3) {
                            // TODO Auto-generated method stub
                             getSelectedItemOfList = sortedList.get(arg2).getStr_movieParam();


                }
            });

            cancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    // TODO Auto-generated method stub

                }
            });

        }

    }
</code></pre>

<p>Here's my updates code:</p>

<pre><code>enter code here
</code></pre>

<p>delete.setOnClickListener(new OnClickListener() {</p>

<pre><code>            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
         adapter.remove(getSelectedItemOfList);
         adapter.notifyDataSetChanged();
            }
        });
        mylist.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView&lt;?&gt; arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub
                SparseBooleanArray checkedPositions =mylist.getCheckedItemPositions();
                if(checkedPositions.get(arg2)==true){
                getSelectedItemOfList = (String) mylist.getItemAtPosition(arg2);
                t1.append(getSelectedItemOfList.toString()+"\n");}
            }
        });
</code></pre>
