0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidのファイルとパッケージ(フォルダ的なの)の作り方。おまけにクラス拡張方法

0
Posted at

すごく基礎の基礎だと思うのですが投稿します(o*。_。)o わ、忘れないように…
わからないけど、qiitaに書くと定着する気がする(✿´ ꒳ ` )いや、気のせいだ、またすぐ忘れる…

ファイルの追加

スクリーンショット 2019-04-08 0.50.02.png

フォルダの追加

スクリーンショット 2019-04-08 0.57.17.png

フォルダの中にファイルを入れる

スクリーンショット 2019-04-08 1.00.38.png

使ってみる

※クラスを使うものと、もともとのクラス(String)の拡張を使ったもの。

TextArrange.kt
package com.example.kiso.Sample

class TextArrange {

    fun sample(){
        println("TextArrangeクラスのsampleです!")
    }
}

fun String.addText(text:String):String {
    return this + text
}
MainActivity.kt
package com.example.kiso

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.kiso.Sample.TextArrange
import com.example.kiso.Sample.addText

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        println("おはよう".addText("ございます"))

        val textArrange = TextArrange()
        textArrange.sample()
    }
}

出力結果
スクリーンショット 2019-04-08 1.07.01.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?