当前位置: 首页>>代码示例>>Scala>>正文


Scala MenuItem类代码示例

本文整理汇总了Scala中android.view.MenuItem的典型用法代码示例。如果您正苦于以下问题:Scala MenuItem类的具体用法?Scala MenuItem怎么用?Scala MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MenuItem类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: delete

//设置package包名称以及导入依赖的类
package sword.langbook.android.activities

import android.view.{MenuItem, Menu, ActionMode}
import android.widget.AbsListView.MultiChoiceModeListener
import sword.langbook.android.R

trait SelectorChoiceModeCallback {
  
  def delete(positions: scala.collection.Set[Int]): Unit
}

case class SelectorChoiceModeListener(callback: SelectorChoiceModeCallback) extends MultiChoiceModeListener {

  private val selected = scala.collection.mutable.BitSet()

  override def onItemCheckedStateChanged(mode: ActionMode, position: Int, id: Long, checked: Boolean): Unit = {
    if (checked) {
      selected.add(position)
    }
    else {
      selected.remove(position)
    }

    // TODO: Move this hardcoded string to the XML resources handling placeholders and plurals
    mode.setTitle(s"${selected.size} word(s) selected")
  }

  override def onDestroyActionMode(mode: ActionMode): Unit = {
    selected.clear()
  }

  override def onCreateActionMode(mode: ActionMode, menu: Menu): Boolean = {
    selected.clear()
    mode.getMenuInflater.inflate(R.menu.selector_multichoice_mode, menu)
    true
  }

  override def onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean = {
    callback.delete(selected)
    mode.finish()
    true
  }

  override def onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean = {
    // Nothing to be done
    false
  }
} 
开发者ID:carlos-sancho-ramirez,项目名称:android-scala-langbook,代码行数:49,代码来源:SelectorChoiceModeListener.scala

示例2: AddressActivity

//设置package包名称以及导入依赖的类
package com.happyheal.happyhealapp.ui.address

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.{MenuItem, Menu}
import com.happyheal.happyhealapp.{R, TR, TypedFindView}
import com.happyheal.happyhealapp.commons.ContextWrapperProvider
import com.happyheal.happyhealapp.modules.persistence.impl.PersistenceServicesComponentImpl
import macroid.{ContextWrapper, Contexts}
import macroid.FullDsl._


class AddressActivity
  extends AppCompatActivity
    with Contexts[AppCompatActivity]
    with ContextWrapperProvider
    with TypedFindView
    with PersistenceServicesComponentImpl
    with AddressComposer {

  override lazy implicit val contextProvider: ContextWrapper = activityContextWrapper

  override def onCreate(savedInstanceState: Bundle): Unit = {
    super.onCreate(savedInstanceState)
    setContentView(TR.layout.address_layout.id)
    toolbar map setSupportActionBar
    getSupportActionBar.setHomeButtonEnabled(true)
    getSupportActionBar().setDisplayHomeAsUpEnabled(true)
    getSupportActionBar().setDisplayShowHomeEnabled(true)
    runUi(addPlaces(List("Silkboard", "Madiwala")))
  }

  override def onCreateOptionsMenu(menu: Menu): Boolean = {
    getMenuInflater.inflate(R.menu.menu_address, menu)
    true
  }

  override def onOptionsItemSelected(item: MenuItem): Boolean = {
    item.getItemId match {
      case R.id.tick =>
        onSubmit()
        return true
      case _ => return super.onOptionsItemSelected(item)
    }
  }

} 
开发者ID:pamu,项目名称:happyheal,代码行数:48,代码来源:AddressActivity.scala


注:本文中的android.view.MenuItem类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。