简体   繁体   English

Android CheckedTextView 全部清除/全选

[英]Android CheckedTextVIew Clear All/Select All

I have a ListView that utilizes a CheckedTextView and a clear all button that has the following code:我有一个使用CheckedTextViewListView和一个具有以下代码的清除所有按钮:

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);
            } 

        }       
    });

When the code executes, each array "songsList" value is set to "Not Checked" correctly, so I know that the button is working.代码执行时,每个数组“songsList”值都正确设置为“未检查” ,因此我知道该按钮正在工作。 However, the CheckedTextView items are not "unticking".但是, CheckedTextView项目并没有“取消勾选”。

Where am I going wrong?我哪里错了?

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.然后我只是调用了我的函数来填充 ListView。 As the ListView is built, it checks the variable in a simple "if" statement, and adds whether to check or uncheck.在构建 ListView 时,它会在一个简单的“if”语句中检查变量,并添加是否选中或取消选中。 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.这来自我的 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最后,这部分来自 cursoradapter getview

if (songsList.get(position).get("songCheckedStatus").equals("Checked")){
holder.checkTextView.setChecked(true);
}else{
 holder.checkTextView.setChecked(false); 
}

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

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