Are you hungry? Implementation of listview linkage of ordering interface
In the last article, I introduced the linkage effect of two listviews in the order interface
It mainly realizes how the two listviews are related to each other. The previous blog reviews the regular use of listview controls. Therefore, this blog mainly analyzes the implementation of the blog of great God at the code level.
On the one hand, it is convenient for yourself to refer to in the future code implementation. On the other hand, it is for novices who have just started Android to learn together.
2、 Final renderings
As shown in the above figure, the effect picture shows the listview cascade imitating the hungry order interface
3、 Difficulties in implementing listview cascading
In order to distinguish, in this article, the listview on the left is called menulistview, and the listview on the right is called itemlistview.
1. Layout of two listviews in the whole activity
2. Manually click item in menulistview. How can itemlistview trigger the associated display
For example, when clicking "new product package" in menulistview, how to display the content of new product package in getview of itemlistview on the right.
3. How is the menulistview associated with the currently clicked item when manually sliding the itemlistview
For example, when manually sliding the itemlistview to "beverage category", the currently clicked item in the menulistview on the left is displayed as beverage category, that is, the background color is white.
4、 Code implementation
1. Layout problem of listview
When I saw this screenshot, I first thought of using the weight display, that is, Android: layout_ weight
First attempt
The effect drawing is as follows:
The second attempt, Android: Layout_ Replace width = "wrap_content" with Android: layout_ width="0dp"
Can be displayed as needed.
2. Manually click item in menulistview. How can itemlistview trigger the associated display
The associated display of menulistview and itemlistview is mainly associated through the function setselection() provided by listview
For example, when the menulistview displays the i-th item, the itemlistview is associated with the first value of the i-th item according to the i-value, and then set it to the current setselection
The implementation in the code is as follows:
Listen for items in menulistview
The first item of item I is obtained through the following code
3. How is the menulistview associated with the currently clicked item when manually sliding the itemlistview
The above is what Xiaobian introduced to you. Are you hungry? The implementation of listview linkage in the ordering interface hopes to help you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!