Skip to content

Commit 9e43a32

Browse files
committed
Create lib deck adapter example
1 parent 4e15bc9 commit 9e43a32

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.example.bloder.deck
2+
3+
import android.content.Context
4+
import android.support.v4.view.PagerAdapter
5+
import android.support.v7.widget.CardView
6+
import android.view.LayoutInflater
7+
import android.view.View
8+
import android.view.ViewGroup
9+
import android.widget.TextView
10+
11+
/**
12+
* Created by bloder on 02/12/17.
13+
*/
14+
class DeckAdapter(private val context: Context) : PagerAdapter() {
15+
16+
private val cards by lazy { genCards() }
17+
18+
override fun instantiateItem(container: ViewGroup?, position: Int): Any {
19+
val view = LayoutInflater.from(context).inflate(R.layout.card, null)
20+
container?.addView(view, 0)
21+
view.findViewById<CardView>(R.id.card).cardBackgroundColor = context.getColorStateList(cards[position].color)
22+
view.findViewById<TextView>(R.id.title).text = cards[position].name
23+
return view
24+
}
25+
26+
override fun isViewFromObject(view: View?, `object`: Any?): Boolean = view == `object`
27+
override fun getCount(): Int = cards.size
28+
}

0 commit comments

Comments
 (0)