当前位置: 首页 > 工具软件 > BGAAdapter > 使用案例 >

BGAAdapter-Android 使用方法

黎腾
2023-12-01

功能介绍

在 AdapterView 和 RecyclerView 中通用的 Adapter 和 ViewHolder。

  •  BGAAdapterViewAdapter 和 BGAViewHolderHelper 用于简化 AdapterView 的子类(如 ListView、GridView)的适配器的编写
  •  BGARecyclerViewAdapter 和 BGAViewHolderHelper 用于简化 RecyclerView 的适配器的编写,支持多 Item 类型,支持添加多个 Header 和 Footer,回调接口里的索引位置已经在库里处理了,不需要开发者自己减去 Header 个数
  •  BGABindingRecyclerViewAdapter 和 BGABindingViewHolder 用于 RecyclerView 结合 DataBinding 使用时简化 RecyclerView 的适配器的编写,支持多 Item 类型,支持添加多个 Header 和 Footer,回调接口里的索引位置已经在库里处理了,不需要开发者自己减去 Header 个数

基本使用:

Gradle 依赖

bga-adapter 后面的「latestVersion」指的是左边这个 maven-central 徽章后面的「数字」,请自行替换

dependencies {
    compile 'com.android.support:recyclerview-v7:latestVersion'
    compile 'cn.bingoogolapple:bga-adapter:latestVersion@aar'
}


Adapter

public class ListAdapter extends BGAAdapterViewAdapter<XXModel> {
    private Context context;
    private int selectPosition=0;
    public List<BGASwipeItemLayout> mOpenedSil = new ArrayList<>();
    public ProjectListAdapter(Context context) {
        super(context, R.layout.item_xxx_list);
        this.context=context;
    }
    @Override
    protected void setItemChildListener(BGAViewHolderHelper viewHolderHelper) {
        viewHolderHelper.setItemChildClickListener(R.id.tv_item_xxxx);
    }

    @Override
    protected void fillData(BGAViewHolderHelper helper, final int position, final XXModel model) {
        helper.setText(R.id.xxxxxx_tv,model.xxxx);
    }
}




Activity里面使用

import cn.bingoogolapple.androidcommon.adapter.BGAOnItemChildClickListener;

public class XXListFragment extends Fragment implements BGAOnItemChildClickListener{
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        if (rootView == null) {
            rootView = inflater.inflate(R.layout.fragment_project_list, null);
            initViews(rootView);  
        }
        return rootView;
    }

    private void initViews(View view) {
		context = this.getActivity();
        projectListview = (ListView) view.findViewById(R.id.project_listview);
        setListAdapter();
    }
	
	 
	private void setListAdapter() { 
		if (projectListAdapter == null) {
			projectListAdapter = new ProjectListAdapter(context);
			projectListAdapter.setData(new ArrayList<XXModel>); 
			projectListAdapter.setOnItemChildClickListener(this); 
			projectListview.setAdapter(projectListAdapter); 
		} else{ 
			projectListAdapter.setData(new ArrayList<XXModel>);
			projectListAdapter.notifyDataSetChanged();
		}
	 }
	@Override public void onItemChildClick(ViewGroup parent, View childView, int position) { 
		if(childView.getId()==R.id.top_layout){ 
			//to do
		} 
	}
}



 类似资料: