I've discovered randomly this small trick in order to have typed views 
inside an Activity.
I would like to share it with you, even thouh you already may know.

Source 
<http://fxthomas.github.io/android-plugin/tutorial/annex-a-using-scala.html>
.

Typed resources

Typed resources are specific to SBT-Android : the plugin generates, along 
with the traditional R.java file, a file called TR.scala, containing 
automatically generated code to handle resources in a type-safe way. You 
don't have to do anything to enable this feature.

*Note: At the time of writing this tutorial, typed resources only work 
inside Activities. Pull requests are welcome to extend that feature.*

To use it, make your Activity subclass extend the TypedActivity trait :

class MyActivity extends Activity with TypedActivity {
  ...}

Anywhere inside the MyActivity class, instead of using findViewById and 
*then* casting it to the right type, you can use the findView method to get 
a view of the right type :

findView(TR.myTextView).setText("Hello, world!")

Compare with the Java version, that requires an unsafe cast :

((TextView)findViewById(R.myTextView)).setText("Hello, world")

-- 
You received this message because you are subscribed to the Google Groups 
"scala-on-android" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to