繁体   English   中英

将textView作为分隔符添加到ListView

[英]Add textView to a ListView as a divider

我试图将TextView添加到我的列表视图,但是当我这样做时,我得到了强制关闭。 我正在尝试在歌曲名称之前的歌曲名称中显示拳头字母。 songlist是一个字符串arraylist,所有这些都在列表视图中。

 Collections.sort(songtitle);
              TextView divide = (TextView)findViewById(R.layout.song);

              adapter = new ArrayAdapter<String>(this,R.layout.song,songtitle);
              int l= 0;
              while(l < adapter.getCount()-1 ){
                  if(songtitle.get(l).charAt(0) == songtitle.get(l+1).charAt(0)){
                      adapter.add(songtitle.get(l));
                     }else{
                      String songname1 = songtitle.get(l);
                      String newString = songname1.substring(0,1);
                      divide.append(newString);// This is where i get the force close  ... I want to display this textView ////

                  }
                 l++;
              }


                setListAdapter(adapter);

        }

如前所述,您应该尝试创建自己的自定义Adapter

public class MyAdapter extends BaseAdapter

在此方法中,您需要重写一些方法,特别是getView()getViewTypeCount() 后者返回List中可能存在的ListItems的类型数(例如,歌曲和字母TextView )。

您应该查看有关将分隔符添加到ListView 本指南

您必须使用CustomAdapter及其自定义视图来执行此操作。

暂无
暂无

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

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