Giter Club home page Giter Club logo

nestlistview's Introduction

作用

解决 ListView 嵌套ListView 问题

NestListView 继承自 Linearlayout

通过 addView 来构造出类似 ListView 样式

原理参考以下文章

http://www.jianshu.com/p/b805091bd4e5

http://blog.csdn.net/lmj623565791/article/details/38902805/

使用方法:

直接拷贝 NestListView.javaCacheHolder.java

对外层的 ListViewAdapter 添加并实现该 NestListView.BindViewGroupListene 接口即可,如下:

public class xxAdapter extends BaseAdapter implements NestListView.BindViewGroupListener{
  	....
    ....
       @Override 
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
       	...
        ...
        viewHolder.mNestListView.setBindViewGroupListener(this);// 绑定当前实现的接口
        viewHolder.mNestListView.setReuse(true);// 开启重用机制
        viewHolder.mNestListView.createNestListView(position,data.size());// 开始创建具体的 NestListView
        return convertView;
    } 
  
    //该方法和重写 BaseAdapter 的 getView 类似
   @Override 
    public View getNestView(int positionInList, int positionInNestList, View convertView){
        NestListViewHolder nestListHolder = null;
        if (convertView == null){
            convertView = LayoutInflater.from(mContext)
                    .inflate(R.layout.nest_list_item, null);
            // 缓存所有 convertView 下的小 view 的实例对象,避免重复 findViewById 
            nestListHolder = new NestListViewHolder(convertView);
            convertView.setTag(nestListHolder);
        } else { 
            nestListHolder = (NestListViewHolder) convertView.getTag();
        } 
		...
        nestListHolder.mTextView.setText(url);
		...
        return convertView;
    } 
}

具体可以参考ListBaseAdapter.java

nestlistview's People

Contributors

flyer88 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

alimogh

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.