Resolve the implementation of ListView linkage-like the ELE. Me ordering interface, listview Linkage

Source: Internet
Author: User

Resolve the implementation of ListView linkage-like the ELE. Me ordering interface, listview Linkage
I. Origin of blogs

Great God Wang Feng egg before a blog copy hungry order interface 2 ListView linkage (http://www.cnblogs.com/wangfengdange/p/5886064.html)

This article mainly implements how two ListView functions to achieve mutual association, just as the previous blog review the conventional use of the ListView control. Therefore, this blog mainly analyzes the implementation of the blog of the great god in the Code layer.

On the one hand, it is convenient for you to refer to the code implementation in the future. On the other hand, the new Android cainiao can learn from each other.

Ii. Final

For example, it is like the ListView cascade on the ELE. Me ordering interface.

Iii. Difficulties in implementing ListView Cascade

In this article, the left-side ListView is called MenuListView, and the right-side ListView is called ItemListView.

1. Layout problem of two ListView in the whole Activity

2. Manually click the item of MenuListView. How does ItemListView trigger associated display?

For example, when you click "new product package" in MenuListView, The getView of ItemListView on the right shows the content of the new product package.

3. How to associate MenuListView with the current item when you manually slide ItemListView

For example, when you manually move ItemListView to "beverage class", the current clicked Item on the left-side MenuListView is displayed as beverage class, that is, the background color is white.

Iv. Code Implementation

1. layout of ListView

When you see this, the first thought is to display the weight, that is, Android: layout_weight.

First Attempt

1 <? Xml version = "1.0" encoding = "UTF-8"?> 2 <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" 3 xmlns: tools = "http://schemas.android.com/tools" 4 android: layout_width = "match_parent" 5 android: layout_height = "match_parent" 6 android: orientation = "horizontal" 7> 8 9 <ListView10 android: id = "@ + id/lv_menu" 11 android: layout_weight = "1" 12 android: layout_height = "match_parent" 13 android: layout_width = "wrap_content"/> 14 <ListView15 android: id = "@ + id/lv_item" 16 android: layout_height = "match_parent" 17 android: layout_weight = "2" 18 android: layout_width = "wrap_content"/> 19 </LinearLayout>View Code

As follows:

In the second attempt, replace android: layout_width = "wrap_content" with android: layout_width = "0dp"

It can be displayed as needed.

2. Manually click the item of MenuListView. How does ItemListView trigger associated display?

The Association display of MenuListView and ItemListView is mainly associated through the setSelection () function of listView.

For example, when MenuListView displays item I, ItemListView associates the item I with the first value based on the I value and sets it as the current setSelection.

The implementation in the Code is as follows:

1. Listen to the item of MenuListView. 2 mListMenu. setOnItemClickListener (new ListView. OnItemClickListener () {3 @ Override 4 public void onItemClick (AdapterView <?> AdapterView, View view, int I, long l) {5 // set the current click item to I Item 6 mMenuAdapter. setSelectItem (I); 7 mMenuAdapter. notifyDataSetInvalidated (); // 8 // set the ItemListView click item to the first item 9 mListItem of the I item. setSelection (mTitleList. get (I); 10} 11 });

The first item of item I is obtained using the following code.

1 mTitleList = new ArrayList <Integer> (); 2 // traverse all items. size (), and then save the values corresponding to different items in the first title, then associate them with the values 3 for (int I = 0; I <mfoodDatas. size (); I ++) {4 if (I = 0) {5 mTitleList. add (I); 6} else if (! TextUtils. equals (mfoodDatas. get (I). getTitle (), mfoodDatas. get (I-1). getTitle () {7 mTitleList. add (I); 8} 9}

3. How to associate MenuListView with the current item when you manually slide ItemListView

1 mListItem. setOnScrollListener (new AbsListView. onScrollListener () {2 3 private int scrollState; 4 5 @ Override 6 public void onScrollStateChanged (AbsListView absListView, int I) {7 this. scrollState = I; 8} 9 10 @ Override11 public void onScroll (AbsListView absListView, 12 int firstVisibleItem, 13 int visibleItemCount, 14 int totalItemCount) {15 if (scrollState = AbsListView. onScrollListener. SCROLL_ST ATE_IDLE) {16 return; 17} 18 // determines whether the current item is the first visible item19 int current = mTitleList. indexOf (firstVisibleItem) in the view; 20 if (current! = CurrentItem & current> 0) {21 currentItem = current; 22 // if not, set the item of menuListView to currentItem to associate with itemListView 23 mMenuAdapter. setSelectItem (currentItem); 24 mMenuAdapter. notifyDataSetInvalidated (); 25} 26 27 28} 29 });
V. Source Code

Source code implementation or visit the Great God Wang Feng egg blog copy ELE. me ordering interface two ListView linkage (http://www.cnblogs.com/wangfengdange/p/5886064.html), this article is just to the ListView cascade implementation for a parsing.

If there are any errors in the analysis in this article, please note that you are welcome to leave a message if you do not understand it. Let's study and make progress together and enter the great god team in the morning.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.