Android 知识点总结 (二十一) Android ListView

相关文章:

Android 知识点总结(目录) https://blog.csdn.net/a136447572/article/details/81027701

1 定义Xml

    
    

2 查找id

   private ListView listView ;
   listView = (ListView) findViewById(R.id.listView);
   list.setAdapter(adapter);

3 Adapter (convertView复用)

 class SaleReportAdapter extends BaseAdapter{

        private ArrayList list ;

        public SaleReportAdapter(ArrayList list) {
            this.list = list;
        }
        @Override
        public int getCount() {
            return list.size();
        }
        @Override
        public Object getItem(int i) {
            return list.get(i);
        }
        @Override
        public long getItemId(int i) {
            return i;
        }
        @Override
        public View getView(int position, View convertView, ViewGroup viewGroup) {
            ViewHolder holder ;
            if (convertView==null){
                holder = new ViewHolder();
                convertView = LayoutInflater.from(SaleReportActivity.this).inflate(R.layout.salereport_item_layout,null);
                holder.text1 = (TextView) convertView.findViewById(R.id.text1);


                convertView.setTag(holder);

            }else{
                holder = (ViewHolder) convertView.getTag();
            }

            SaleReportBeans.RecordListBean beans = list.get(position);

            holder.text1.setText(beans.getStartDate()+"--"+beans.getEndDate()+"|||||"+beans.getCtg().getSale()+"--------"+beans.getPil().getSale());

            return convertView;
        }

        class ViewHolder{

            TextView text1 ;


        }
    }

4 listView 的属性

// 修改listView的分割线
1 android:divider="@android:color/darker_gray"
2 android:dividerHeight="10dp"
或
3  android:divider="@null"


//ListView的滚动条
 android:scrollbars="none"

//通过listSelector属性设置Cell选中后的颜色:
android:listSelector="#000000"


//使用系统自带的透明色来实现:
android:listSelector="@android:color/transparent"

listview的滚动监听

 pullList.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {
            }
            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                if (firstVisibleItem == 0) {
                //到顶部了
                    mSwipeLayout.setEnabled(true);
                } else if (visibleItemCount + firstVisibleItem == totalItemCount) {        
                //到底部了
                    mSwipeLayout.setEnabled(false);
                } else {
                //在中间
                    mSwipeLayout.setEnabled(false);
                }
            }
        });

你可能感兴趣的:(andriod)