Skip to content

Instantly share code, notes, and snippets.

@hirauchg
hirauchg / SampleModel.kt
Last active May 19, 2019 14:57
[Kotlin] RecyclerViewでリスト表示を実装する - リストのModelクラスの作成 - SampleModel.kt
data class SampleModel (
val id: Int,
val name: String
)
@hirauchg
hirauchg / SampleAdapter.kt
Last active May 19, 2019 15:13
RecyclerViewでリスト表示を実装する - Adapterの実装 - 1
class SampleAdapter(val mListener: SampleAdapterListener): RecyclerView.Adapter<SampleAdapter.ViewHolder>() {
interface SampleAdapterListener {
fun onClickCard(position: Int)
fun onClickDelete(position: Int)
}
private val mUI = SampleAdapterUI()
private var mSampleModelList = listOf<SampleModel>()
@hirauchg
hirauchg / SampleActivity.kt
Last active May 19, 2019 15:28
RecyclerViewでリスト表示を実装する - リスト表示画面の実装 - 1
class SampleActivity : BaseActivity(), SampleAdapter.SampleAdapterListener {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val ui = SampleActivityUI()
ui.setContentView(this)
// テストデータ
val sampleModelList = arrayListOf<SampleModel>()
@hirauchg
hirauchg / SampleActivityUI.kt
Last active May 19, 2019 15:25
RecyclerViewでリスト表示を実装する - リスト表示画面の実装 - 2
class SampleActivityUI : AnkoComponent<SampleActivity> {
lateinit var mRecyclerView: RecyclerView
override fun createView(ui: AnkoContext<SampleActivity>) = with(ui) {
verticalLayout {
mRecyclerView = recyclerView {
layoutManager = LinearLayoutManager(ctx, LinearLayoutManager.VERTICAL, false)
}.lparams(width = matchParent) {
topMargin = dip(5)
@hirauchg
hirauchg / strings.xml
Created April 14, 2019 03:30
[Kotlin] アプリの多言語対応(ローカライズ) - 各言語のvaluesディレクトリを追加 - values/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="thank_you">Thank you</string>
</resources>
@hirauchg
hirauchg / strings.xml
Created April 14, 2019 03:33
[Kotlin] アプリの多言語対応(ローカライズ) - 各言語のvaluesディレクトリを追加 - values-ja/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="thank_you">ありがとう</string>
</resources>
@hirauchg
hirauchg / strings.xml
Created April 14, 2019 03:34
[Kotlin] アプリの多言語対応(ローカライズ) - 各言語のvaluesディレクトリを追加 - values-es/strings.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="thank_you">Gracias</string>
</resources>
@hirauchg
hirauchg / SampleDBHelper.kt
Last active May 19, 2019 14:08
AnkoでSQLiteデータベースを実装する - データベースとテーブルの作成 - 1
class SampleDBHelper(ctx: Context) : ManagedSQLiteOpenHelper(ctx, DB_SAMPLE, null, DB_VERSION) {
companion object {
const val DB_SAMPLE = "db_sample"
const val DB_VERSION = 1
const val TABLE_SAMPLE = "table_sample"
const val CULM_ID = "id"
const val CULM_TEXT = "text"
@hirauchg
hirauchg / SampleModel.kt
Last active May 19, 2019 14:13
AnkoでSQLiteデータベースを実装する - モデルの作成 - 1
data class SampleModel (
val id: Int,
val text: String,
val number: Int
)
@hirauchg
hirauchg / SampleManager.kt
Last active May 19, 2019 14:16
AnkoでSQLiteデータベースを実装する - Managerの作成 - 1
class SampleManager(ctx: Context) {
private val mDB = SampleDBHelper.getInstance(ctx)
fun getSampleModelList(): List<SampleModel> {
lateinit var sampleModelList: List<SampleModel>
mDB.use {
sampleModelList = select(SampleDBHelper.TABLE_SAMPLE).parseList(classParser())
}
return sampleModelList