本文整理汇总了Scala中android.widget.AdapterView类的典型用法代码示例。如果您正苦于以下问题:Scala AdapterView类的具体用法?Scala AdapterView怎么用?Scala AdapterView使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AdapterView类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: ListDialog
//设置package包名称以及导入依赖的类
package com.android.perrier1034.post_it_note.ui.dialog
import android.app.AlertDialog.Builder
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.view.View
import android.widget.AdapterView.OnItemClickListener
import android.widget.{AdapterView, ArrayAdapter}
object ListDialog {
def newInstance(title: Option[String], listItems: Seq[ListItem], icon: Option[Int]): DialogFragment = {
val bun = new Bundle
title foreach { bun.putString("title", _) }
bun.putSerializable("items", listItems.toArray)
icon foreach { bun.putInt("icon", _)}
val instance = new ListDialog
instance.setArguments(bun)
instance
}
}
class ListDialog extends DialogFragment {
override def onCreateDialog(savedInstanceState: Bundle): Dialog = {
def createLabelArray: Array[String] = getListItems map { _.label }
def getListItems = getArguments.getSerializable("items").asInstanceOf[Array[ListItem]]
val adapter = new ArrayAdapter[String](getActivity, android.R.layout.simple_list_item_1, createLabelArray)
val builder = new Builder(getActivity).setAdapter(adapter, null)
val title = getArguments.getString("title", null)
if (title != null) builder.setTitle(getArguments.getString("title"))
val icon = getArguments.getInt("icon", 0)
if (icon > 0) builder.setIcon(icon)
val dialog = builder.create()
val listView = dialog.getListView
listView.setOnItemClickListener(new OnItemClickListener {
override def onItemClick(adapterView: AdapterView[_], view: View, i: Int, l: Long): Unit = {
getListItems(i).execute()
dismiss()
}
})
dialog
}
}