ここらのプロパティの初期化です.
public class TasksActivity extends AppCompatActivity {
private static final String CURRENT_FILTERING_KEY = "CURRENT_FILTERING_KEY";
private DrawerLayout mDrawerLayout;
private TasksPresenter mTasksPresenter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.tasks_act);
// Set up the toolbar.
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar ab = getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
// Set up the navigation drawer.
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark);
android-architecture/TasksActivity.java at todo-mvp · googlesamples/android-architecture
lateinit
Properties and Fields - Kotlin Programming Language
onCreate() などコンストラクタでないライフサイクルに関係するメソッド内での初期化に利用するとよい. 基本的に var と合わせて mutable に.
class TasksActivity : AppCompatActivity() {
private lateinit var mDrawerLayout: DrawerLayout
private lateinit var mTasksPresenter: TasksPresenter
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.tasks_act)
// Set up the toolbar.
val toolbar = findViewById(R.id.toolbar) as Toolbar
setSupportActionBar(toolbar)
val ab = supportActionBar
ab?.setHomeAsUpIndicator(R.drawable.ic_menu)
ab?.setDisplayHomeAsUpEnabled(true)
// Set up the navigation drawer.
mDrawerLayout = findViewById(R.id.drawer_layout) as DrawerLayout
mDrawerLayout.setStatusBarBackground(R.color.colorPrimaryDark)
Convert Java File to Kotlin の後に その1「メンバとコンストラクタ」
Convert Java File to Kotlin の後に その2 「apply」
Convert Java File to Kotlin の後に その3 「Null Safety」