Jamendo学习笔记-2:ListView分栏的实现

ListView 分栏( Columnar ListView )的好处在于,区分内容,便于用户操作选择。核心思想是:在指定位置插入标题内容。
 
实现方法如下:
 
 
1,  实现 Adapter areAllItemsEnabled() 方法和 isEnabled() 方法 , 确定内容
 
显然, ListView Item 中,标题不可被操作,内容部分可响应点击( click )和长按( longClick )时间。设置如下:
@Override

                                     public boolean areAllItemsEnabled() {

                                                         // TODO Auto-generated method stub

                                                         return false;

                                     }

    

                                     @Override

                                     public boolean isEnabled( int position) {

                                                         // TODO Auto-generated method stub

                                                         if (position == 0 || position == 4) { //

                                                                         return false;

                                                        } else {

                                                                         return true;

                                                        }

                                     }

 
2, ListView 要显示的内容中,添加两个标题内容。如增加数组长度或 StringArray 长度等。
3,  getView ()方法中,做判断,代码如下:
 
if (position == 0 || position == 4) {
        TextView textView = new TextView(MainActivity. this);
        textView.setText(mMainListContents[position]);
        textView.setBackgroundColor(android.R.color.black);
         return textView;
      }
4,效果如下:

你可能感兴趣的:(ListView,职场,休闲,分栏,jamendo)