有基于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);
    }

}


  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45.
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
  • 52.
  • 53.
  • 54.
  • 55.
  • 56.
  • 57.
  • 58.
  • 59.
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
  • 67.
  • 68.
  • 69.
  • 70.
  • 71.
  • 72.
  • 73.
  • 74.
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
  • 81.
  • 82.
  • 83.
  • 84.
  • 85.
  • 86.
  • 87.
  • 88.
  • 89.
  • 90.
  • 91.
  • 92.
  • 93.
  • 94.
  • 95.
  • 96.
  • 97.
  • 98.
  • 99.
  • 100.
  • 101.
  • 102.
  • 103.
  • 104.
  • 105.
  • 106.
  • 107.
  • 108.
  • 109.
  • 110.
  • 111.
  • 112.
  • 113.
  • 114.
  • 115.
  • 116.
  • 117.
  • 118.
  • 119.
  • 120.
  • 121.
  • 122.
  • 123.
  • 124.
  • 125.
  • 126.
  • 127.
  • 128.
  • 129.
  • 130.
  • 131.
  • 132.
  • 133.
  • 134.
  • 135.
  • 136.
  • 137.
  • 138.
  • 139.
  • 140.
  • 141.
  • 142.
  • 143.
  • 144.
  • 145.
  • 146.
  • 147.
  • 148.
  • 149.
  • 150.
  • 151.
  • 152.
  • 153.
  • 154.
  • 155.
  • 156.
  • 157.
  • 158.
  • 159.
  • 160.
  • 161.
  • 162.
  • 163.
  • 164.
  • 165.
  • 166.
  • 167.
  • 168.
  • 169.
  • 170.
  • 171.
  • 172.
  • 173.
  • 174.
  • 175.
  • 176.
  • 177.
  • 178.
  • 179.
  • 180.
  • 181.
  • 182.
  • 183.
  • 184.
  • 185.
  • 186.
  • 187.
  • 188.
  • 189.
  • 190.
  • 191.
  • 192.
  • 193.
  • 194.
  • 195.
  • 196.
  • 197.
  • 198.
  • 199.
  • 200.
  • 201.
  • 202.
  • 203.
  • 204.
  • 205.
  • 206.
  • 207.
  • 208.
  • 209.
  • 210.
  • 211.
  • 212.
  • 213.
  • 214.
  • 215.
  • 216.
  • 217.
  • 218.
  • 219.
  • 220.
  • 221.
  • 222.
  • 223.
  • 224.
  • 225.
  • 226.
  • 227.
  • 228.
  • 229.
  • 230.
  • 231.
  • 232.
  • 233.
  • 234.
  • 235.
  • 236.
  • 237.
  • 238.
  • 239.
  • 240.
  • 241.
  • 242.
  • 243.
  • 244.
  • 245.
  • 246.
  • 247.
  • 248.
  • 249.
  • 250.
  • 251.
  • 252.
  • 253.
  • 254.
  • 255.
  • 256.
  • 257.
  • 258.
  • 259.
  • 260.
  • 261.
  • 262.
  • 263.
  • 264.
  • 265.
  • 266.
  • 267.
  • 268.
  • 269.
  • 270.
  • 271.
  • 272.
  • 273.
  • 274.
  • 275.
  • 276.
  • 277.
  • 278.
  • 279.
  • 280.
  • 281.
  • 282.
  • 283.
  • 284.
  • 285.
  • 286.
  • 287.
  • 288.
  • 289.
  • 290.
  • 291.
  • 292.
  • 293.
  • 294.
  • 295.
  • 296.
  • 297.
  • 298.
  • 299.
  • 300.
  • 301.
  • 302.
  • 303.
  • 304.
  • 305.
  • 306.
  • 307.
  • 308.
  • 309.
  • 310.
  • 311.
  • 312.
  • 313.
  • 314.
  • 315.
  • 316.
  • 317.
  • 318.
  • 319.
  • 320.
  • 321.
  • 322.
  • 323.
  • 324.
  • 325.
  • 326.
  • 327.
  • 328.
  • 329.
  • 330.
  • 331.
  • 332.
  • 333.
  • 334.
  • 335.
  • 336.
  • 337.
  • 338.
  • 339.
  • 340.
  • 341.
  • 342.
  • 343.
分享
微博
QQ
微信
回复
2021-06-23 10:35:22


相关问题
HarmonyOS 第三方APP跳转
708浏览 • 1回复 待解决
鸿蒙第三方哪些引入方法?
306浏览 • 1回复 已解决
第三方js库迁移吗?
3851浏览 • 1回复 待解决
开发第三方SDK如何编译?
14497浏览 • 2回复 待解决
HarmonyOS 使用第三方应用打开
938浏览 • 1回复 待解决
HarmonyOS 依赖第三方库报错
944浏览 • 1回复 待解决
HarmonyOS 如何加载第三方页面
633浏览 • 1回复 待解决
native交叉编译第三方
1071浏览 • 1回复 待解决
第三方怎么装鸿蒙系统?
6711浏览 • 1回复 待解决
鸿蒙哪些支持第三方UI框架吗?
4625浏览 • 1回复 待解决
如何引入自己第三方”库
1450浏览 • 1回复 待解决
HarmonyOS如何移植第三方MCU?
10272浏览 • 1回复 待解决
HarmonyOS 如何启动第三方APP
797浏览 • 1回复 待解决
图片剪切第三方框架
954浏览 • 1回复 待解决
HarmonyOS支持第三方列表
2354浏览 • 1回复 待解决