Skip to content

Instantly share code, notes, and snippets.

@levinotik
Created May 23, 2012 02:23
Show Gist options
  • Save levinotik/2772880 to your computer and use it in GitHub Desktop.
Save levinotik/2772880 to your computer and use it in GitHub Desktop.
class MyView(c: Context) extends RelativeLayout(c) {
import AndroidConversions._;
val tv = new TextView(c)
var params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.addRule(RelativeLayout.CENTER_IN_PARENT)
tv.setLayoutParams(params)
tv.setText("hello")
tv.setId(10)
addView(tv)
val b = new Button(c)
params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT)
params.addRule(RelativeLayout.BELOW, 10)
b.setLayoutParams(params)
b.setText("click me!")
b.onClick = {Toast.makeText(this, "You have clicked the button", Toast.LENGTH_LONG).show()}
addView(b)
}
[error] /Users/levinotik/Google Drive/code/Projects/scala/MyAndroidAppProject/src/com/example/myandroid/MyAndroidAppActivity.scala:41: value onClick is not a member of android.widget.Button
[error] b.onClick = {Toast.makeText(this, "You have clicked the button", Toast.LENGTH_LONG).show()}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment