简体   繁体   中英

saving checkbox state in listview in android?

I am fetching playlist from my mobile and showing my songs in listview along with multiple checkboxes..Now, i need to save state of checkboxes which will be reloaded when user again start the app.can you suggest how this can be done ??

for fetching songs from system playlist ...code that i have written is:

ListView list = (ListView) findViewById(R.id.songlist);
String[] projection = { MediaStore.Audio.Playlists.Members._ID,
                MediaStore.Audio.Playlists.Members.TITLE,
                 MediaStore.Audio.Playlists.Members.DATA,
                MediaStore.Audio.Playlists.Members.AUDIO_ID,
                MediaStore.Audio.Playlists.Members.ARTIST };

    Cursor cursor = managedQuery(
            // 1 is the id of playlist  MediaStore.Audio.Playlists.Members.getContentUri("external", 1), projection,
                MediaStore.Audio.Media.IS_MUSIC + " != 0 ", null, null);

SimpleCursorAdapter a = new SimpleCursorAdapter(this, R.layout.list_item, cursor,
                new String[] { MediaStore.Audio.Playlists.Members.TITLE }, new int[] { R.id.checkbox });
        this.setListAdapter(a);
        list.setAdapter(a);

You could override the onDestroy method of your Activity, saving the contents of your adapter to a file. See http://developer.android.com/guide/topics/data/data-storage.html for reference on how to save to a file. You can easily access the adapater's contents using getItem(int position) on your SimpleAdapter.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM