diff --git a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java index 59d1aff632214f1d5a3b5e4b5ce19fc8adb8c7af..62f975f0dc16efd7e1a6fb294d671881223dd98e 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/MainAbility.java @@ -11,6 +11,7 @@ import com.lxj.xpopupdemo.stackLayout.AllAnimatorDemo; import com.lxj.xpopupdemo.stackLayout.CustomAnimatorDemo; import com.lxj.xpopupdemo.stackLayout.CustomPopupDemo; import com.lxj.xpopupdemo.stackLayout.ImageViewerDemo; +import com.lxj.xpopupdemo.stackLayout.ListContainerDemo; import com.lxj.xpopupdemo.stackLayout.PartShadowDemo; import com.lxj.xpopupdemo.stackLayout.QuickStartDemo; import ohos.aafwk.ability.Ability; @@ -53,7 +54,8 @@ public class MainAbility extends Ability { ComponentContainer view3 = new AllAnimatorDemo(this); ComponentContainer view4 = new CustomPopupDemo(this); ComponentContainer view5 = new CustomAnimatorDemo(this); - // 将view装入数组 + ComponentContainer view6 = new ListContainerDemo(this); + // 将commonent装入数组 pageview = new ArrayList(); pageview.add(view0); pageview.add(view1); @@ -62,6 +64,7 @@ public class MainAbility extends Ability { pageview.add(view3); pageview.add(view4); pageview.add(view5); + pageview.add(view6); radioContainer = (RadioContainer) findComponentById(ResourceTable.Id_radio_container); pageSlider = (PageSlider) findComponentById(ResourceTable.Id_pagerSlider); diff --git a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ListContainerDemo.java b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ListContainerDemo.java new file mode 100644 index 0000000000000000000000000000000000000000..6ef0fe312376a0a0d0bc4cb6f08ef5d12b9d972c --- /dev/null +++ b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/ListContainerDemo.java @@ -0,0 +1,86 @@ +package com.lxj.xpopupdemo.stackLayout; + +import com.lxj.xpopup.XPopup; +import com.lxj.xpopup.interfaces.OnSelectListener; +import com.lxj.xpopup.provider.EasyProvider; +import com.lxj.xpopupdemo.ResourceTable; +import ohos.agp.components.Component; +import ohos.agp.components.ListContainer; +import ohos.app.Context; + +import java.util.ArrayList; + +/** + * Description: + * Create by dance, at 2021/10/18 + */ +public class ListContainerDemo extends BaseStackLayout { + ListContainer listContainer; + + public ListContainerDemo(Context context) { + super(context); + } + + @Override + protected int getLayoutId() { + return ResourceTable.Layout_stacklayout_list_container_demo; + } + + ArrayList dataStr; + + @Override + public void init(Component component) { + listContainer = (ListContainer) component.findComponentById(ResourceTable.Id_listContainer); + + dataStr = new ArrayList<>(); + for (int i = 0; i < 20; i++) { + dataStr.add("条目" + i); + } + + final EasyProvider commonAdapter = new EasyProvider(getContext(), dataStr, ResourceTable.Layout_simple_list_item_2) { + @Override + protected void bind(ViewHolder holder, String itemData, int position) { + holder.setText(ResourceTable.Id_text1, itemData); + holder.getView(ResourceTable.Id_text1).setClickedListener(new ClickedListener() { + @Override + public void onClick(Component component) { + new XPopup.Builder(getContext()) + .hasShadowBg(false) + .isDestroyOnDismiss(true) // 对于只使用一次的弹窗,推荐设置这个 + .atView(component) // 依附于所点击的Commonent,内部会自动判断在上方或者下方显示 + .isComponentMode(true, component) // Component实现模式 + .asAttachList(new String[]{"分享", "编辑"}, + new int[]{ResourceTable.Media_icon, ResourceTable.Media_icon}, + new OnSelectListener() { + @Override + public void onSelect(int position, String text) { + toast("click " + text); + } + }, 0, 0).show(); + } + }); + } + }; + listContainer.setItemProvider(commonAdapter); + listContainer.setItemClickedListener(new ListContainer.ItemClickedListener() { + @Override + public void onItemClicked(ListContainer listContainer, Component component, int position, long id) { + new XPopup.Builder(getContext()) + .hasShadowBg(false) + .isDestroyOnDismiss(true) // 对于只使用一次的弹窗,推荐设置这个 + .atView(component) // 依附于所点击的Commonent,内部会自动判断在上方或者下方显示 + .isCenterHorizontal(true) // 是否与依附的Commonent水平居中对齐 + .asAttachList(new String[]{"分享", "编辑", "不带icon不带icon", "分享分享分享"}, + new int[]{ResourceTable.Media_icon, ResourceTable.Media_icon}, + new OnSelectListener() { + @Override + public void onSelect(int position, String text) { + toast("click " + text); + } + }, 0, 0).show(); + } + }); + + } + +} diff --git a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java index e8a24f12a59c13701e8209fb5d0a3ba0778f1925..bdd810f09b6b9adad106e6f78a6bba4e66c2e2de 100644 --- a/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java +++ b/entry/src/main/java/com/lxj/xpopupdemo/stackLayout/QuickStartDemo.java @@ -72,13 +72,13 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked component.findComponentById(ResourceTable.Id_btnBubbleAttachPopup1).setClickedListener(this); component.findComponentById(ResourceTable.Id_btnBubbleAttachPopup2).setClickedListener(this); - // 必须在事件发生前,调用这个方法来监视View的触摸 + // 必须在事件发生前,调用这个方法来监视Commonent的触摸 final XPopup.Builder builder = new XPopup.Builder(getContext()) .watchView(component.findComponentById(ResourceTable.Id_btnShowAttachPoint)); component.findComponentById(ResourceTable.Id_btnShowAttachPoint).setLongClickedListener(new LongClickedListener() { @Override public void onLongClicked(Component component) { - XPopup.fixLongClick(component); // 能保证弹窗弹出后,下层的View无法滑动 + XPopup.fixLongClick(component); // 能保证弹窗弹出后,下层的Commonent无法滑动 builder.asAttachList(new String[]{"置顶11", "复制", "删除", "编辑编辑编辑编辑" }, null, new OnSelectListener() { @@ -231,13 +231,13 @@ public class QuickStartDemo extends BaseStackLayout implements Component.Clicked .asCustom(new PagerBottomPopup(getContext())) .show(); break; - case ResourceTable.Id_tv1: // 依附于某个View的Attach类型弹窗 + case ResourceTable.Id_tv1: // 依附于某个Commonent的Attach类型弹窗 case ResourceTable.Id_tv2: case ResourceTable.Id_tv3: new XPopup.Builder(getContext()) .hasShadowBg(false) .isDestroyOnDismiss(true) // 对于只使用一次的弹窗,推荐设置这个 - .atView(component) // 依附于所点击的View,内部会自动判断在上方或者下方显示 + .atView(component) // 依附于所点击的Commonent,内部会自动判断在上方或者下方显示 .isComponentMode(true, component) // Component实现模式 .asAttachList(new String[]{"分享", "编辑", "不带icon不带icon", "分享分享分享"}, new int[]{ResourceTable.Media_icon, ResourceTable.Media_icon}, diff --git a/entry/src/main/resources/base/layout/ability_main.xml b/entry/src/main/resources/base/layout/ability_main.xml index 9695884dd07477525b8ca28c199fe7d035d544c4..236b9b737cdd0466c6c4408d4401f3076b36b015 100644 --- a/entry/src/main/resources/base/layout/ability_main.xml +++ b/entry/src/main/resources/base/layout/ability_main.xml @@ -83,6 +83,15 @@ ohos:text_color_off="#aaa" ohos:text_color_on="#fff" ohos:text_size="15fp"/> + + diff --git a/entry/src/main/resources/base/layout/simple_list_item_2.xml b/entry/src/main/resources/base/layout/simple_list_item_2.xml new file mode 100644 index 0000000000000000000000000000000000000000..15a40b96882b1fcdf0c56d8e7f4971404018bc9c --- /dev/null +++ b/entry/src/main/resources/base/layout/simple_list_item_2.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/entry/src/main/resources/base/layout/stacklayout_list_container_demo.xml b/entry/src/main/resources/base/layout/stacklayout_list_container_demo.xml new file mode 100644 index 0000000000000000000000000000000000000000..8177774790aac39781025cbabd806d13b40874c6 --- /dev/null +++ b/entry/src/main/resources/base/layout/stacklayout_list_container_demo.xml @@ -0,0 +1,25 @@ + + + + + + + + \ No newline at end of file