Created
October 20, 2018 08:09
-
-
Save worker8/0f7d9bc5b7ebb2b6380957c99388835e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RandomAdapter(val dataArray: List) : AccordionAdapter { | |
override fun onCreateViewHolderForTitle(parent: ViewGroup): AccordionView.ViewHolder { | |
return TitleViewHolder.create(parent) | |
} | |
override fun onCreateViewHolderForContent(parent: ViewGroup): AccordionView.ViewHolder { | |
return ContentViewHolder.create(parent) | |
} | |
override fun onBindViewForTitle(viewHolder: AccordionView.ViewHolder, position: Int, arrowDirection: AccordionAdapter.ArrowDirection) { | |
val dataModel = dataArray[position] | |
(viewHolder as TitleViewHolder).itemView.apply { | |
titleTextView.text = dataModel.title | |
when (arrowDirection) { | |
AccordionAdapter.ArrowDirection.UP -> titleArrowIcon.text = "▲" | |
AccordionAdapter.ArrowDirection.DOWN -> titleArrowIcon.text = "▼" | |
AccordionAdapter.ArrowDirection.NONE -> titleArrowIcon.text = "" | |
} | |
} | |
} | |
override fun onBindViewForContent(viewHolder: AccordionView.ViewHolder, position: Int) { | |
val dataModel = dataArray[position] | |
(viewHolder as ContentViewHolder).itemView.apply { | |
contentTextView.text = dataModel.desc | |
} | |
} | |
override fun getItemCount() = dataArray.size | |
} | |
class TitleViewHolder(itemView: View) : AccordionView.ViewHolder(itemView) { | |
companion object { | |
fun create(parent: ViewGroup): TitleViewHolder { | |
return TitleViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.row_title, parent, false)) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment