core_layout_more_list_3
core_layout_more_list_2
class MainActivity : AppCompatActivity() {
private lateinit var popWindow: PopWindowManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
initView()
}
private var oneIndex = 0
private var oneData: MoreListBean? = null
private var twoIndex = 0
private var twoData: MoreListBean? = null
private var treeIndex = 0
private var treeData: MoreListBean? = null
private fun initView() {
val zoneView = LayoutInflater.from(this).inflate(R.layout.core_layout_more_list_3, null, false)
popWindow = PopWindowManager(this, zoneView, From.TOP, 300)
val listViewOne = zoneView.findViewById<RecyclerView>(R.id.more_list_one)
val listViewTwo = zoneView.findViewById<RecyclerView>(R.id.more_list_two)
val listViewTree = zoneView.findViewById<RecyclerView>(R.id.more_list_tree)
listViewOne.layoutManager = LinearLayoutManager(this)
listViewTwo.layoutManager = LinearLayoutManager(this)
listViewTree.layoutManager = LinearLayoutManager(this)
val oneAdapter = MoreListAdapter(this, TYPE_One, true)
val twoAdapter = MoreListAdapter(this, TYPE_Two, true)
val treeAdapter = MoreListAdapter(this, TYPE_Tree, true)
listViewOne.adapter = oneAdapter
listViewTwo.adapter = twoAdapter
listViewTree.adapter = treeAdapter
oneAdapter.setMoreListListener { i, data ->
oneIndex = i
oneData = data
twoIndex = 0
twoData = null
treeIndex = 0
treeData = null
twoAdapter.clear()
treeAdapter.clear()
// 获取网络数据
// 设置第二级的数据
if (data.title != "全部") {
val datas = getTwoData(data.title)
datas.add(0, MoreListBean("全部"))
twoAdapter.setData(datas)
}
}
twoAdapter.setMoreListListener { i, data ->
twoIndex = i
twoData = data
treeIndex = 0
treeData = null
treeAdapter.clear()
// 获取网络数据
// 设置第三级的数据
if (data.title != "全部") treeAdapter.setData(getTreeData(data.title))
}
treeAdapter.setMoreListListener { i, data ->
treeIndex = i
treeData = data
// 获取网络数据
}
// 设置第一级的数据
oneAdapter.setData(getOneData().apply {
add(0, MoreListBean("全部"))
})
tv.setOnClickListener {
oneAdapter.setCurrent(oneIndex)
twoAdapter.setCurrent(twoIndex)
treeAdapter.setCurrent(treeIndex)
popWindow.setAnchorView(it)
popWindow.show()
}
}
private fun getOneData(): ArrayList<MoreListBean> {
return ArrayList<MoreListBean>().apply {
repeat(10) {
add(MoreListBean("第一级${it}"))
}
}
}
private fun getTwoData(titie: String): ArrayList<MoreListBean> {
return ArrayList<MoreListBean>().apply {
repeat(10) {
add(MoreListBean("第二级${titie}-${it}"))
}
}
}
private fun getTreeData(title: String): ArrayList<MoreListBean> {
return ArrayList<MoreListBean>().apply {
repeat(10) {
add(MoreListBean("第三级${title}-${it}"))
}
}
}
}