本文整理汇总了Scala中android.support.v7.widget.RecyclerView类的典型用法代码示例。如果您正苦于以下问题:Scala RecyclerView类的具体用法?Scala RecyclerView怎么用?Scala RecyclerView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RecyclerView类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Scala代码示例。
示例1: BaseViewHolder
//设置package包名称以及导入依赖的类
package sword.langbook.android.viewholders
import android.support.v7.widget.RecyclerView
import android.view.View
abstract class BaseViewHolder(view: View) extends RecyclerView.ViewHolder(view)
object BaseViewHolder {
object types {
val checkableEntry = 0
val descriptionHeader = 1
val sectionEntry = 2
val sectionHeader = 3
val symbol = 4
}
}
开发者ID:carlos-sancho-ramirez,项目名称:android-scala-langbook,代码行数:17,代码来源:BaseViewHolder.scala
示例2: SymbolDetailsAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.support.v7.widget.RecyclerView
import android.view.View.OnClickListener
import android.view.{View, ViewGroup}
import sword.langbook.android.R
import sword.langbook.android.viewholders._
import sword.langbook.db.Symbol
case class SymbolDetailsAdapter(activity: BaseActivity, symbol: Symbol) extends RecyclerView.Adapter[BaseViewHolder] {
val alphabets = symbol.alphabetsWhereIncluded.toVector
val alphabetSectionSize = if (alphabets.nonEmpty) alphabets.size + 1 else 0
override val getItemCount = 1 + alphabetSectionSize
override def getItemViewType(position: Int) = {
if (position == 1) BaseViewHolder.types.sectionHeader
else BaseViewHolder.types.sectionEntry
}
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = {
viewType match {
case BaseViewHolder.types.`sectionHeader` => SectionHeaderViewHolder.newInstance(viewGroup)
case BaseViewHolder.types.`sectionEntry` => SectionEntryViewHolder.newInstance(viewGroup)
}
}
override def onBindViewHolder(vh: BaseViewHolder, position: Int): Unit = {
vh match {
case holder: SectionHeaderViewHolder =>
holder.textView.setText(activity.getString(R.string.alphabetsWhereIncluded))
case holder: SectionEntryViewHolder =>
val textView = holder.textView
if (position == 0) {
textView.setText(s"Unicode: ${symbol.unicode.toHexString}")
textView.setClickable(false)
}
else {
val alphabet = alphabets(position - 2)
textView.setText(alphabet.suitableTextForLanguage(activity.preferredLanguage).getOrElse(""))
textView.setOnClickListener(new OnClickListener {
override def onClick(v: View): Unit = {
AlphabetDetails.openWith(activity, alphabetEncodedKey = alphabet.key.encoded)
}
})
textView.setClickable(true)
}
}
}
}
开发者ID:carlos-sancho-ramirez,项目名称:android-scala-langbook,代码行数:52,代码来源:SymbolDetailsAdapter.scala
示例3: AlphabetDetailsAdapter
//设置package包名称以及导入依赖的类
package sword.langbook.android.activities
import android.app.Activity
import android.support.v7.widget.RecyclerView
import android.util.DisplayMetrics
import android.view.View.OnClickListener
import android.view.{View, ViewGroup}
import sword.langbook.android.R
import sword.langbook.android.viewholders.SymbolViewHolder
import sword.langbook.db.Alphabet
object AlphabetDetailsAdapter {
def apply(activity: Activity, alphabet: Alphabet) = {
val metrics = new DisplayMetrics()
activity.getWindowManager.getDefaultDisplay.getMetrics(metrics)
val columns = metrics.widthPixels / activity.getResources.getDimensionPixelSize(R.dimen.alphabetDetailsSymbolSide)
new AlphabetDetailsAdapter(activity, alphabet, columns)
}
}
case class AlphabetDetailsAdapter(activity: Activity, alphabet: Alphabet, spanCount: Int) extends RecyclerView.Adapter[SymbolViewHolder] {
val symbols = alphabet.symbols.toSeq.sortWith(_.unicode < _.unicode)
val chars = symbols.map(_.unicode.toChar)
override val getItemCount = symbols.size
override def onCreateViewHolder(viewGroup: ViewGroup, viewType: Int) = {
SymbolViewHolder.newInstance(viewGroup)
}
override def onBindViewHolder(vh: SymbolViewHolder, position: Int): Unit = {
vh.textView.setText("" + chars(position))
vh.textView.setOnClickListener(new OnClickListener {
override def onClick(v: View): Unit = {
SymbolDetails.openWith(activity, symbol = symbols(position))
}
})
}
}
开发者ID:carlos-sancho-ramirez,项目名称:android-scala-langbook,代码行数:41,代码来源:AlphabetDetailsAdapter.scala
示例4: DividerAdder
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui
import android.content.Context
import android.content.res.TypedArray
import android.graphics.drawable.Drawable
import android.graphics.{Canvas, Rect}
import android.support.v7.widget.RecyclerView
object DividerAdder {
private val ATTRS: Array[Int] = Array[Int](android.R.attr.listDivider)
}
class DividerAdder extends RecyclerView.ItemDecoration {
private var mDivider: Drawable = null
def this(context: Context) {
this()
val array: TypedArray = context.obtainStyledAttributes(DividerAdder.ATTRS)
mDivider = array.getDrawable(0)
array.recycle
}
@SuppressWarnings(Array("deplicated"))
override def getItemOffsets(outRect: Rect, itemPosition: Int, parent: RecyclerView) {
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight)
}
override def onDraw(c: Canvas, parent: RecyclerView) {
drawVertical(c, parent)
}
def drawVertical(c: Canvas, parent: RecyclerView) {
val left: Int = parent.getPaddingLeft
val right: Int = parent.getWidth - parent.getPaddingRight
val childCount: Int = parent.getChildCount
for (i <- 0 until parent.getChildCount) {
val child = parent.getChildAt(i)
val params = child.getLayoutParams.asInstanceOf[RecyclerView.LayoutParams]
val top = child.getBottom + params.bottomMargin
val bottom = top + mDivider.getIntrinsicHeight
mDivider.setBounds(left, top, right, bottom)
mDivider.draw(c)
}
}
}
开发者ID:perrier1034,项目名称:Post-it-Note,代码行数:47,代码来源:DividerAdder.scala
示例5: PkgViewHolder
//设置package包名称以及导入依赖的类
package com.yhsif.notifbot
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import android.widget.TextView
class PkgViewHolder(v: View) extends RecyclerView.ViewHolder(v) {
def setIcon(icon: Drawable) = {
v.findViewById(R.id.icon).asInstanceOf[ImageView].setImageDrawable(icon)
}
def setName(name: String) = {
v.findViewById(R.id.name).asInstanceOf[TextView].setText(name)
}
def setBackground(i: Int) = {
if (i % 2 == 0) {
v.setBackgroundColor(v.getContext().getColor(R.color.even_background))
} else {
v.setBackgroundColor(v.getContext().getColor(R.color.odd_background))
}
}
}
开发者ID:fishy,项目名称:notifbot,代码行数:26,代码来源:PkgViewHolder.scala
示例6: PkgAdapter
//设置package包名称以及导入依赖的类
package com.yhsif.notifbot
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.View
import scala.collection.mutable.ListBuffer
class PkgAdapter(
var list: ListBuffer[PkgData],
val listener: View.OnClickListener)
extends RecyclerView.Adapter[PkgViewHolder] {
override def onCreateViewHolder(parent: ViewGroup, vt: Int): PkgViewHolder = {
val v =
LayoutInflater
.from(parent.getContext())
.inflate(R.layout.pkg_item, parent, false)
v.setOnClickListener(listener)
return new PkgViewHolder(v)
}
override def onBindViewHolder(vh: PkgViewHolder, i: Int): Unit = {
vh.setIcon(list.apply(i).icon)
vh.setName(list.apply(i).name)
vh.setBackground(i)
}
override def getItemCount(): Int = list.length
override def onAttachedToRecyclerView(rv: RecyclerView): Unit = {
super.onAttachedToRecyclerView(rv)
}
def remove(i: Int) = {
list.remove(i)
notifyDataSetChanged()
}
}
开发者ID:fishy,项目名称:notifbot,代码行数:41,代码来源:PkgAdapter.scala
示例7: PkgViewHolder
//设置package包名称以及导入依赖的类
package com.yhsif.autonotif
import android.graphics.drawable.Drawable
import android.support.v7.widget.RecyclerView
import android.view.View
import android.widget.ImageView
import android.widget.TextView
class PkgViewHolder(v: View) extends RecyclerView.ViewHolder(v) {
def setIcon(icon: Drawable) = {
v.findViewById(R.id.icon).asInstanceOf[ImageView].setImageDrawable(icon)
}
def setName(name: String) = {
v.findViewById(R.id.name).asInstanceOf[TextView].setText(name)
}
def setBackground(i: Int) = {
if (i % 2 == 0) {
v.setBackgroundColor(v.getContext().getColor(R.color.even_background))
} else {
v.setBackgroundColor(v.getContext().getColor(R.color.odd_background))
}
}
}
开发者ID:fishy,项目名称:autonotif,代码行数:26,代码来源:PkgViewHolder.scala
示例8: PkgAdapter
//设置package包名称以及导入依赖的类
package com.yhsif.autonotif
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup
import android.view.View
import scala.collection.mutable.ListBuffer
class PkgAdapter(
var list: ListBuffer[PkgData],
val listener: View.OnClickListener)
extends RecyclerView.Adapter[PkgViewHolder] {
override def onCreateViewHolder(parent: ViewGroup, vt: Int): PkgViewHolder = {
val v =
LayoutInflater
.from(parent.getContext())
.inflate(R.layout.pkg_item, parent, false)
v.setOnClickListener(listener)
return new PkgViewHolder(v)
}
override def onBindViewHolder(vh: PkgViewHolder, i: Int): Unit = {
vh.setIcon(list.apply(i).icon)
vh.setName(list.apply(i).name)
vh.setBackground(i)
}
override def getItemCount(): Int = list.length
override def onAttachedToRecyclerView(rv: RecyclerView): Unit = {
super.onAttachedToRecyclerView(rv)
}
def remove(i: Int) = {
list.remove(i)
notifyDataSetChanged()
}
}
开发者ID:fishy,项目名称:autonotif,代码行数:41,代码来源:PkgAdapter.scala
注:本文中的android.support.v7.widget.RecyclerView类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论