有基于ListContainer下拉刷新 像安卓中listview的第三方下拉刷新布局

我找到了有XRecyclerView  

https://gitee.com/openharmony-tpc/XRecyclerView

看了一会也不知道怎么使用

ListContainer
2021-06-21 15:36:06
浏览
收藏 0
回答 2
待解决
回答 2
按赞同
/
按时间
鸿蒙开发者

不会引用在哪里 ,最好贴代码 ,你这种问题啥都没有 估计都不知道怎么回答的。

分享
微博
QQ
微信
回复1
2021-06-22 08:52:02
ZikH
//listcontainer所在布局
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    xmlns:app="http://schemas.ohos.com/hap/res-auto"
    ohos:height="match_parent"
    ohos:width="match_parent">
<com.tuesda.walker.circlerefresh.CircleRefreshLayout
    ohos:id="$+id:refreshLayout"
    ohos:height="match_parent"
    ohos:width="match_parent"
    ohos:alignment="center"
    app:AniBackColor="#ff8b90af"
    app:AniForeColor="#ffffffff"
    app:CircleSmaller="60">

    <DependentLayout
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:orientation="vertical">

    <ListContainer
        ohos:background_element="$graphic:background_ability_main"
        ohos:id="$+id:list_container"
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:visibility="visible"
        />
    </DependentLayout>
</com.tuesda.walker.circlerefresh.CircleRefreshLayout>
</DependentLayout>


// list item布局
<DirectionalLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_content"
    ohos:width="match_parent"
    ohos:orientation="vertical">
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:width="match_parent"
    ohos:height="match_content"
    ohos:background_element="$graphic:background_ability_main">
    <Text
        ohos:margin="20px"
        ohos:left_padding="100px"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:id="$+id:item_titel"
        ohos:text="这是小小的标题"
        ohos:text_size="60px"
        />
    <Image
        ohos:left_padding="100px"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:image_src="$media:logo"
        ohos:align_start="$id:item_titel"
        ohos:top_padding="120px"
        ohos:id="$+id:item_image_hot"
        />

        <Image
            ohos:top_padding="20px"
            ohos:right_padding="150px"
            ohos:align_top="$id:item_titel"
            ohos:align_parent_end="true"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:image_src="$media:icon"
            ohos:id="$+id:item_image_logo"
            />

        <Text
            ohos:left_padding="50px"
            ohos:top_padding="120px"
            ohos:end_of="$id:item_image_hot"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:id="$+id:item_time"
            ohos:text="2021-12-25"
            ohos:text_size="40px"
            />

    <Text
        ohos:top_padding="120px"
        ohos:height="match_content"
        ohos:width="match_content"
        ohos:end_of="$id:item_time"
        ohos:left_padding="50px"
        ohos:text="吉林农科"
        ohos:text_size="40px"
        ohos:id="$+id:item_creater"
        />
    <Component
        ohos:top_margin="20px"
        ohos:below="$id:item_time"
        ohos:height="1vp"
        ohos:width="match_parent"
        ohos:background_element="#CCCCCC"/>

</DependentLayout>
</DirectionalLayout>

//java 实体
public class item {
    private String titel;
    private String time;
    private String creater;
    private int isHot;

    public item() {

    }

    public item(String titel, String time, String creater, int isHot) {
        this.titel = titel;
        this.time = time;
        this.creater = creater;
        this.isHot = isHot;
    }

    public String getTitel() {
        return titel;
    }

    public void setTitel(String titel) {
        this.titel = titel;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public int getIsHot() {
        return isHot;
    }

    public void setIsHot(int isHot) {
        this.isHot = isHot;
    }

    @Override
    public String toString() {
        return "item{" +
                "titel='" + titel + '\'' +
                ", time='" + time + '\'' +
                ", creater='" + creater + '\'' +
                ", isHot=" + isHot +
                '}';
    }
}

//适配器
public class ListAdapter extends BaseItemProvider {

    private final List<item> list;
    //上下文对象
    private Context context;
    //解析器
    private final LayoutScatter inflater;


    public ListAdapter(Context context, List<item> list) {
        this.list = list;
        this.context = context;
        //视图解析器
        this.inflater = LayoutScatter.getInstance(context);
    }

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

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

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

    @Override
    public Component getComponent(int i, Component component, ComponentContainer componentContainer) {
      Component view = component;
      final ViewHolder holder;
      if (component == null){
          view = inflater.parse(ResourceTable.Layout_ability_item,componentContainer,false);
          holder = new ViewHolder();

          holder.text_titel = (Text) view.findComponentById(ResourceTable.Id_item_titel);

          holder.text_time = (Text) view.findComponentById(ResourceTable.Id_item_time);

          holder.text_creater = (Text) view.findComponentById(ResourceTable.Id_item_creater);

          holder.image_ishot = (Image) view.findComponentById(ResourceTable.Id_item_image_hot);

          view.setTag(holder);


      }else {
          holder = (ViewHolder) view.getTag();
      }

      holder.text_titel.setText((list.get(i).getTitel()));

      holder.text_time.setText(list.get(i).getTime());

      holder.text_creater.setText(list.get(i).getCreater());

      if (list.get(i).getIsHot() == 1){
            holder.image_ishot.setVisibility(Component.VISIBLE);
      }else {
          holder.image_ishot.setVisibility(Component.INVISIBLE);
      }


        return view;
    }
    static class ViewHolder{
        Text text_titel;
        Text text_time;
        Text text_creater;
        Image image_ishot;
    }
}
//ability
public class MainAbility extends Ability {

    private static final HiLogLabel TAG = new HiLogLabel(HiLog.LOG_APP,0x00201,"ggg");

    private CircleRefreshLayout mRefreshLayout;
    private ListContainer mListView;
    private ListAdapter mListAdapter;

    List<item> list = new ArrayList<>();

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        HiLog.info(TAG, "执行了");



//        String Url = "http://zxb.free.vipnps.vip/ProjectTest/harmonyList";
//        TaskDispatcher globalTaskDispatcher = getGlobalTaskDispatcher(TaskPriority.DEFAULT);
//        Revocable revocable = globalTaskDispatcher.asyncDispatch(new Runnable() {
//            @Override
//            public void run() {
//                ZZRHttp.get(Url, new ZZRCallBack.CallBackString() {
//                    @Override
//                    public void onFailure(int i, String s) {
//                        new ToastDialog(getContext())
//                                .setText("数据请求失败,失败原因:" + s + i)
//                                .show();
//                    }
//                    @Override
//                    public void onResponse(String s) {
//                        //jackson
//                        ObjectMapper objectMapper = new ObjectMapper();
//
//                        try {
//
//                            list = objectMapper.readValue(s, objectMapper.getTypeFactory().constructParametricType(List.class, item.class));
//
//                        } catch (JsonProcessingException e) {
//                            e.printStackTrace();
//
//                            HiLog.info(TAG, e.toString());
//
//                            new ToastDialog(getContext())
//                                    .setText("数据解析失败")
//                                    .show();
//                        }
//                    }
//                });
//            }
//        });
        init();
       mRefreshLayout = (CircleRefreshLayout) findComponentById(ResourceTable.Id_refreshLayout);

        mListView = (ListContainer) findComponentById(ResourceTable.Id_list_container);

        mRefreshLayout.setOnRefreshListener(new CircleRefreshLayout.OnCircleRefreshListener() {
            @Override
            public void completeRefresh() {

            }

            @Override
            public void refreshing() {


            }
        });

        mListAdapter = new ListAdapter(getContext(),list);
        mListView.setItemProvider(mListAdapter);
        mListAdapter.notifyDataChanged();

    }

    public void init(){

        for (int i = 0 ; i < 20 ; i ++){
            item it  = new item();
            it.setTitel("这是假数据" + i);
            it.setCreater("吉林农科");
            it.setTime("2021-16-88");
            it.setIsHot(1);

            list.add(it);
        }

    }
    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

}


分享
微博
QQ
微信
回复
2021-06-23 10:35:22
相关问题
开发第三方SDK如何编译?
8672浏览 • 2回复 待解决
HarmonyOS如何移植第三方MCU?
3863浏览 • 1回复 待解决
如何设置第三方hap开机自动打开
268浏览 • 1回复 待解决
在引用第三方组件代码时
1244浏览 • 1回复 待解决
鸿蒙左右下拉栏能不能互换?
10848浏览 • 4回复 待解决