「Android/kotlin/helloworld」の版間の差分
提供: 初心者エンジニアの簡易メモ
(→helloworld) |
|||
行17: | 行17: | ||
} | } | ||
} | } | ||
+ | |||
+ | res/layout/activity_main.xml | ||
+ | <pre> | ||
+ | <?xml version="1.0" encoding="utf-8"?> | ||
+ | <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
+ | xmlns:app="http://schemas.android.com/apk/res-auto" | ||
+ | xmlns:tools="http://schemas.android.com/tools" | ||
+ | android:layout_width="match_parent" | ||
+ | android:layout_height="match_parent" | ||
+ | tools:context=".MainActivity"> | ||
+ | <TextView | ||
+ | android:id="@+id/text1" | ||
+ | android:layout_width="wrap_content" | ||
+ | android:layout_height="wrap_content" | ||
+ | android:text="Hello World!" | ||
+ | app:layout_constraintBottom_toBottomOf="parent" | ||
+ | app:layout_constraintLeft_toLeftOf="parent" | ||
+ | app:layout_constraintRight_toRightOf="parent" | ||
+ | app:layout_constraintTop_toTopOf="parent" /> | ||
+ | |||
+ | </androidx.constraintlayout.widget.ConstraintLayout> | ||
+ | </pre> |
2020年2月13日 (木) 15:07時点における版
helloworld
MainActivity.kt
class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) var logic = SampleLogic() var str = logic.execLogic(); // var str : String = logic.execLogic(); // 型指定もできる Log.d("test", "Helloworld=" + str); } }
Samplelogic.kt
class SampleLogic { fun execLogic(): String { return "Helloworld" } }
res/layout/activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".MainActivity"> <TextView android:id="@+id/text1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" /> </androidx.constraintlayout.widget.ConstraintLayout>