创建模拟的数据
List getSongs(){
HiLog.error(LABEL_LOG,“getSongs==”);
List list = new ArrayList();
List list2 = new ArrayList();
List list3 = new ArrayList();
for (int i=0; i<100; i++) {
list.add(new SongData(“歌曲名称:”+i,“歌手:”+i));
}
int i=0;
for (Object data:list) {
if (i=2){//i为需要的列数
i=0;
list3.add(new NewSongModel(list2));
list2=new ArrayList<>();
}
list2.add((SongData) data);
i++;
}
list3.add(new NewSongModel(list2));
HiLog.error(LABEL_LOG,“list3==”+list3.size());
return list3;
}
NewSongModel 类:
public class NewSongModel {
private List songModels;
public NewSongModel(List songModels) {
this.songModels = songModels;
}
public List getSongModels() {
return songModels;
}
public void setSongModels(List songModels) {
this.songModels = songModels;
}
}
Provider类的实现
public class MultSongProvider extends RecycleItemProvider {
private static final HiLogLabel LABEL_LOG = new HiLogLabel(3, 0xD001100, “Demo”);
private List<NewSongModel> datas=new ArrayList<>();
private AbilitySlice mSlice;
LayoutScatter layoutScatter;
public MultSongProvider(AbilitySlice mSlice, Context context) {
this.mSlice = mSlice;
this.layoutScatter = LayoutScatter.getInstance(context);
}
public void setDataMos(List<NewSongModel> cityMos){
this.datas.clear();
this.datas.addAll(cityMos);
HiLog.error(LABEL_LOG,"datas=="+datas.size());
notifyDataChanged();
}
@Override
public int getCount() {
return datas.size();
}
@Override
public Object getItem(int i) {
return datas.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
private void onItemClick(UserModel cityMo,int position){
}
@Override
public Component getComponent(int pos, Component component, ComponentContainer componentContainer) {
/* Component component1= LayoutScatter.getInstance(mSlice).parse(ResourceTable.Layout_layout_user_item,null,false);
User mo=dataMos.get(i);
Text text= (Text) component1.findComponentById(ResourceTable.Id_txt_user_item);
text.setText("姓名:"+mo.getName()+" 年龄:"+mo.getAge()+" phone:"+mo.getPhone());
return component1;*/
Component component1= LayoutScatter.getInstance(mSlice).parse(ResourceTable.Layout_songitem_layout,null,false);
if (!(component1 instanceof ComponentContainer)){
return null;
}
ComponentContainer container= (ComponentContainer) component1;
//component相当于Android中的view,其他的和Android中ListView的适配器adapter差不多。
// 名字区别也不大,不过Android中ListView基本被淘汰了。
NewSongModel usersModel=datas.get(pos);
for (int j = 0; j < usersModel.getSongModels().size(); j++) {
SongData songModel=usersModel.getSongModels().get(j);
DirectionalLayout directionalLayout= (DirectionalLayout) LayoutScatter.getInstance(mSlice).parse(ResourceTable.Layout_mulitsong_item,null,false);
Text songName= (Text) directionalLayout.findComponentById(ResourceTable.Id_songName);
Text songer= (Text) directionalLayout.findComponentById(ResourceTable.Id_songer);
songName.setText(songModel.getName());
songer.setText(songModel.getSinger());
DirectionalLayout.LayoutConfig buttonLayoutConfig = new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_CONTENT, ComponentContainer.LayoutConfig.MATCH_CONTENT, DirectionalLayout.HORIZONTAL, 1);//设置布局的权重值,使添加进来的布局均分
directionalLayout.setPaddingBottom(20);
directionalLayout.setPaddingTop(20);
directionalLayout.setLayoutConfig(buttonLayoutConfig);
container.addComponent(directionalLayout);
}
return component1;
}
public interface onDeleteListener{
void onItemClick(UserModel userBean, int position);
}
}