在 AdapterView 和 RecyclerView 中通用的 Adapter 和 ViewHolder。
基本使用:
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);
}
}
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
}
}
}