SHARE
TWEET

Untitled

a guest Jan 16th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class UserListRecyclerViewAdapter(private var mUserList: List<User>):
  2.         RecyclerView.Adapter<UserListRecyclerViewAdapter.ViewHolder>() {
  3.  
  4.     companion object {
  5.         const val TAG_NAME = "tag_name"
  6.         const val TAG_AGE = "tag_age"
  7.     }
  8.  
  9.     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
  10.         return ViewHolder(UserListRecyclerViewAdapterUI().createView(AnkoContext.create(parent.context, parent)))
  11.     }
  12.  
  13.     override fun getItemCount(): Int {
  14.         return mUserList.size
  15.     }
  16.  
  17.     override fun onBindViewHolder(holder: ViewHolder, position: Int) {
  18.         val item = mUserList.get(position)
  19.         holder.name.text = "名前:" + item.name
  20.         holder.age.text = "年齢:" + item.age.toString()
  21.     }
  22.  
  23.     inner class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
  24.         val name: TextView = view.findViewWithTag(TAG_NAME)
  25.         val age: TextView = view.findViewWithTag(TAG_AGE)
  26.     }
  27. }
  28.  
  29. class UserListRecyclerViewAdapterUI : AnkoComponent<ViewGroup> {
  30.     override fun createView(ui: AnkoContext<ViewGroup>) = with(ui) {
  31.  
  32.         verticalLayout {
  33.             linearLayout {
  34.                 textView { tag = UserListRecyclerViewAdapter.TAG_NAME }
  35.                 textView { tag = UserListRecyclerViewAdapter.TAG_AGE }
  36.             }
  37.         }
  38.     }
  39. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top