core_layout_more_list_3
    image.png
    core_layout_more_list_2
    image.png

    1. class MainActivity : AppCompatActivity() {
    2. private lateinit var popWindow: PopWindowManager
    3. override fun onCreate(savedInstanceState: Bundle?) {
    4. super.onCreate(savedInstanceState)
    5. setContentView(R.layout.activity_main)
    6. initView()
    7. }
    8. private var oneIndex = 0
    9. private var oneData: MoreListBean? = null
    10. private var twoIndex = 0
    11. private var twoData: MoreListBean? = null
    12. private var treeIndex = 0
    13. private var treeData: MoreListBean? = null
    14. private fun initView() {
    15. val zoneView = LayoutInflater.from(this).inflate(R.layout.core_layout_more_list_3, null, false)
    16. popWindow = PopWindowManager(this, zoneView, From.TOP, 300)
    17. val listViewOne = zoneView.findViewById<RecyclerView>(R.id.more_list_one)
    18. val listViewTwo = zoneView.findViewById<RecyclerView>(R.id.more_list_two)
    19. val listViewTree = zoneView.findViewById<RecyclerView>(R.id.more_list_tree)
    20. listViewOne.layoutManager = LinearLayoutManager(this)
    21. listViewTwo.layoutManager = LinearLayoutManager(this)
    22. listViewTree.layoutManager = LinearLayoutManager(this)
    23. val oneAdapter = MoreListAdapter(this, TYPE_One, true)
    24. val twoAdapter = MoreListAdapter(this, TYPE_Two, true)
    25. val treeAdapter = MoreListAdapter(this, TYPE_Tree, true)
    26. listViewOne.adapter = oneAdapter
    27. listViewTwo.adapter = twoAdapter
    28. listViewTree.adapter = treeAdapter
    29. oneAdapter.setMoreListListener { i, data ->
    30. oneIndex = i
    31. oneData = data
    32. twoIndex = 0
    33. twoData = null
    34. treeIndex = 0
    35. treeData = null
    36. twoAdapter.clear()
    37. treeAdapter.clear()
    38. // 获取网络数据
    39. // 设置第二级的数据
    40. if (data.title != "全部") {
    41. val datas = getTwoData(data.title)
    42. datas.add(0, MoreListBean("全部"))
    43. twoAdapter.setData(datas)
    44. }
    45. }
    46. twoAdapter.setMoreListListener { i, data ->
    47. twoIndex = i
    48. twoData = data
    49. treeIndex = 0
    50. treeData = null
    51. treeAdapter.clear()
    52. // 获取网络数据
    53. // 设置第三级的数据
    54. if (data.title != "全部") treeAdapter.setData(getTreeData(data.title))
    55. }
    56. treeAdapter.setMoreListListener { i, data ->
    57. treeIndex = i
    58. treeData = data
    59. // 获取网络数据
    60. }
    61. // 设置第一级的数据
    62. oneAdapter.setData(getOneData().apply {
    63. add(0, MoreListBean("全部"))
    64. })
    65. tv.setOnClickListener {
    66. oneAdapter.setCurrent(oneIndex)
    67. twoAdapter.setCurrent(twoIndex)
    68. treeAdapter.setCurrent(treeIndex)
    69. popWindow.setAnchorView(it)
    70. popWindow.show()
    71. }
    72. }
    73. private fun getOneData(): ArrayList<MoreListBean> {
    74. return ArrayList<MoreListBean>().apply {
    75. repeat(10) {
    76. add(MoreListBean("第一级${it}"))
    77. }
    78. }
    79. }
    80. private fun getTwoData(titie: String): ArrayList<MoreListBean> {
    81. return ArrayList<MoreListBean>().apply {
    82. repeat(10) {
    83. add(MoreListBean("第二级${titie}-${it}"))
    84. }
    85. }
    86. }
    87. private fun getTreeData(title: String): ArrayList<MoreListBean> {
    88. return ArrayList<MoreListBean>().apply {
    89. repeat(10) {
    90. add(MoreListBean("第三级${title}-${it}"))
    91. }
    92. }
    93. }
    94. }