1

我有一个使用CheckedTextView的ListView和一个具有以下代码的清除所有按钮:

btnClearAll.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            int listsize = songsList.size();
            filelv = (ListView)getView().findViewById(R.id.FileList);
            checkedCount = 0;
            for (int i=0; i<listsize-1; i++) {
                // if(currentPlayList.get(i).equals ("Checked")){
                songsList.get(i).get("songCheckedStatus").equals("Not Checked");

                filelv.setItemChecked(i, false);
            } 

        }       
    });

当代码执行时,每个数组“songsList”的值都被正确设置为“Not Checked”,所以我知道该按钮正在工作。但是,CheckedTextView项目并没有“取消勾选”。

我哪里错了?

4

1 回答 1

0

olution:

As mentioned above, I just set up a global variable and passed whether I wanted to Select All or Clear All to it. Then I just called my function for populating the ListView. As the ListView is built, it checks the variable in a simple "if" statement, and adds whether to check or uncheck. The cursor adapter then does the check/uncheck as it reruns.

//The code for clearing all.
btnClearAll.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            checkedCount = 0;

            GetMusicMode = "ClearAll";
            GetMusic getMusic = new GetMusic();
            getMusic.execute();
        }       
    });

And this from my data grabber for the ListView.

 ....
 String track_Title = null;
 String track_Path = null;
 String track_Artist = null;
 String track_Album = null;
 String track_ID = null;
 String track_TrackNumber = null;
 String track_AlbumID = null;
 String track_ArtistID = null;
 String track_Checked = null;

 if (Constants.GetMusicMode.equals("SelectAll")){
track_Checked = "Checked";
}else{
track_Checked = "Not Checked";
 }
 .....

 .....

 HashMap<String, String> song = new HashMap<String, String>();
song.put("songTitle", track_Title);
song.put("songPath", track_Path);
song.put("songArtist", track_Artist);
song.put("songAlbum", track_Album);
song.put("songTrackNumber", track_TrackNumber);
song.put("songID", track_ID);
song.put("songAlbumID", track_AlbumID);
song.put("songArtistID", track_ArtistID);
song.put("songCheckedStatus", track_Checked);


// Adding each song to SongList
songsList.add(song);

    ....throw to cursor adapter

and finally, this section from the cursoradapter getview

if (songsList.get(position).get("songCheckedStatus").equals("Checked")){
holder.checkTextView.setChecked(true);
}else{
 holder.checkTextView.setChecked(false); 
}
于 2012-09-11T20:33:06.897 回答