This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun setOnClickListener(listener: (view: View) -> Unit) { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
public void main() { | |
// Anonymous Implementation: | |
myView.setOnClickListener(new OnClickListener() { | |
@Override | |
void onClick(View v) { | |
logger.debug("View Clicked!"); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface OnClickListener { | |
void onClick(View v); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fails: | |
// If onNext is a method Reference | |
// and onError is an object | |
import io.reactivex.Observable | |
import io.reactivex.functions.Consumer | |
class MyErrorHandler : Consumer<Throwable> { | |
override fun accept(t: Throwable?) { TODO() } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity : Activity { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.my_layout) | |
} | |
fun useViews() { | |
my_view.text = "Hello World" | |
arrayOf(first, second).forEach { it.text = "Hello!" } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin: 'kotlin-android-extensions' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity : Activity { | |
private val myView: TextView by bindView(R.id.my_view) | |
private val views: List<TextView> by bindViews(R.id.first, R.id.second) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.my_layout) | |
} | |
fun useViews() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
@BindView(R.id.my_view) TextView myView; | |
@BindViews({R.id.first, R.id.second}) TextView[] views; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.my_layout); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyActivity extends Activity { | |
private View myView; | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.my_layout); | |
// If you only want to look up once: | |
myView = findViewById(R.id.my_view); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Completable data = Completable.mergeArrayDelayError( | |
widgetRepository.observeWidgets() | |
.take(1) | |
.ignoreElements() | |
.subscribeOn(Schedulers.io()) | |
.observeOn(AndroidSchedulers.mainThread()) | |
fooRepository.observeFoo() | |
.take(1) | |
.ignoreElements() | |
.subscribeOn(Schedulers.io()) |