简体   繁体   English

在Android的列表视图中保存复选框状态?

[英]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. 您可以覆盖Activity的onDestroy方法,将适配器的内容保存到文件中。 See http://developer.android.com/guide/topics/data/data-storage.html for reference on how to save to a file. 有关如何保存到文件的参考,请参见http://developer.android.com/guide/topics/data/data-storage.html You can easily access the adapater's contents using getItem(int position) on your SimpleAdapter. 您可以使用SimpleAdapter上的getItem(int position)轻松访问adapater的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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