daimajia / daimajia/AndroidSwipeLayout

AndroidBinding ListViewAdapter and AndroidSwipeLayout

Open
#337 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
12.3k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

Hi,

I try implement androidbindig with ListViewAdpater.
In demo application in class ListViewAdapter.java in method generateView wrote this code:

@Override
public View generateView(int position, ViewGroup parent) {
MyListAdapterBinding binding = DataBindingUtil.inflate(LayoutInflater.from(getContext()),R.layout.check, parent, false);
View convertView = binding.getRoot();
binding.setModel(this.getItem(position));
convertView.setTag(binding);
return convertView;
}

In my list I see diffrent items on pages with not the same model for row:

![screenshot_2016-06-28-21-20-04 1](https://cloud.githubusercontent.com/assets/4520009/16429241/09aec618-3d76-11e6-957b-7b4e13fb1e92.jpg)
![screenshot_2016-06-28-21-20-15 1](https://cloud.githubusercontent.com/assets/4520009/16429245/11850910-3d76-11e6-81b1-9f0b8bed9202.jpg)

Can anybody helps with this idea ?

When I wrote class extends BaseAdapter and implement inside AndroidBinding it works:
public class ListViewAndroidBindingAdapter extends BaseAdapter {

```
private Context mContext;
private List dataList;

public ListViewAndroidBindingAdapter(Context mContext) {
this.mContext = mContext;
dataList = ListDataManager.getListDataModelList();
}

@Override
public int getCount() {
return dataList.size();
}

@Override
public Object getItem(int position) {
return dataList.get(position);
}

public ListDataModel getModel(int position) {
return (ListDataModel)getItem(position);
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {

ListviewadapterItemBinding binding = null;
if(convertView == null) {
binding = DataBindingUtil.inflate(LayoutInflater.from(mContext),R.layout.listviewadapter_item, parent, false);
convertView = binding.getRoot();
}
else {
binding = (ListviewadapterItemBinding)convertView.getTag();
}

binding.setViewModel(new ListViewAdapterViewModel(getModel(position)));
convertView.setTag(binding);

return convertView;
}
```

}

![screenshot_2016-06-28-21-19-50](https://cloud.githubusercontent.com/assets/4520009/16429325/6754238a-3d76-11e6-8937-425e47c7f790.jpg)
![screenshot_2016-06-28-21-19-38](https://cloud.githubusercontent.com/assets/4520009/16429328/6c164704-3d76-11e6-9baa-d55ce15eeba7.jpg)

I prepare simple solution for this two kind of situations:
https://bitbucket.org/margiel/androidbindingpoc

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.