Hi,
I'm using a SimpleAdapter to display two strings on each row of a
ListView and want to be able to remove rows. The ListView initially
displays correctly but when I click a row to remove it a null pointer
error is thrown. Can't seem to find any documentation or examples
anywhere. Can anybody advise on the best way to do this?

public class add_pal extends Activity {
    Button doneButton;
    private ArrayAdapter<String> palAdapter;
    List<Map<String, String>> pal_list;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_pal);

        pal_list = new ArrayList<Map<String, String>>();
        for (Pal p: hello_listview.arPals)
{                                                   // arPals has
already been filled
            Map<String, String> map = new HashMap<String, String>();
            map.put("Name", p.name);
            map.put("Title", p.title);
            pal_list.add(map);
        }
        String[] from = {"Name", "Title"};
        int[] to = {R.id.listItemName, R.id.listItemTitle};

        SimpleAdapter palAdapter = new
SimpleAdapter(this.getApplicationContext(),
                                                                                
                        pal_list,
                                                                                
                        R.layout.listitem,
                                                                                
                        from,
                                                                                
                        to);

        ListView listView = (ListView) findViewById(R.id.addPalList);
        listView.setAdapter(palAdapter);
        registerForContextMenu(listView);
        listView.setOnItemClickListener(listView_clicked);

    } // End of OnCreate

    AdapterView.OnItemClickListener listView_clicked = new
AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView parent, View v, int
position, long id) {
            palAdapter.remove(palAdapter.getItem(position));
 
PalAdapter.notifyDataSetChanged();                                              
    //
This section here is the bit not working
        }
    };


} // End of class

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to