In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article "android how to achieve imitation JD.com commodity attribute screening function" most people do not understand, so the editor summed up the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "android how to achieve imitation JD.com commodity attribute screening function" article it.
Effect:
Clicking the filter button will pop up a self-encapsulated popupWindow, and the practical method is very simple; two lines of code are displayed directly; (except for initialization data, of course)
This is a little different from the previously used streaming layout: streaming layout
Previously, a single category was used, and it was not widely used in the project; this filtering function is almost all Copy from the project except for the data.
The whole popupWindow layout is a custom ListView, which mainly controls the height of the listview.
If there is less data, it is adaptive. If there is more data, the height is limited to half the height of the screen.
Custom ListView:
Public class CustomHeightListView extends ListView {private Context mContext; public CustomHeightListView (Context context) {this (context, null);} public CustomHeightListView (Context context, AttributeSet attrs) {this (context, attrs, 0);} public CustomHeightListView (Context context, AttributeSet attrs, int defStyleAttr) {super (context, attrs, defStyleAttr); init (context);} private void init (Context context) {mContext = context } @ Override protected void onMeasure (int widthMeasureSpec, int heightMeasureSpec) {try {/ / maximum height is displayed as half of the height of the screen content Display display = ((Activity) mContext) .getWindowManager () .getDefaultDisplay (); DisplayMetrics d = new DisplayMetrics (); display.getMetrics (d) / / set the height of the control not to exceed half of the height of the screen (d.heightPixels / 2, there is a clear button below, so you can also change it to the height you want) heightMeasureSpec = MeasureSpec.makeMeasureSpec (d.heightPixels / 2-200, MeasureSpec.AT_MOST);} catch (Exception e) {e.printStackTrace ();} / recalculate the height and width of the control (widthMeasureSpec, heightMeasureSpec) }}
Each item in ListView is a streaming layout:
The whole popupwindow is encapsulated in a class. You only need to pass the data source to it when you create it, and you can show it directly when it is practical.
FlowPopWindow = new FlowPopWindow (MainActivity.this, dictList); flowPopWindow.showAsDropDown (ivBack)
When you click OK, you can directly set a monitor:
FlowPopWindow.setOnConfirmClickListener (new FlowPop_Window.OnConfirmClickListener () {@ Override public void onConfirmClick () {StringBuilder sb = new StringBuilder (); for (FiltrateBean fb: dictList) {List cdList = fb.getChildren (); for (int x = 0; x < cdList.size ()) {FiltrateBean.Children children = cdList.get (x) If (children.isSelected ()) sb.append (fb.getTypeName () + ":" + children.getValue () + " ");}} if (! TextUtils.isEmpty (sb.toString ()) Toast.makeText (MainActivity.this, sb.toString (), Toast.LENGTH_LONG) .show () }} the above is about the content of this article on "how to imitate JD.com 's commodity attribute screening function in android". I believe everyone has a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more related knowledge, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.