This article was written in 3 previous articles,
** 4th day of article posting every day for 7 days **
It has become
I'll put the code to use below, but see the article three before for the detailed features of this app!
--java version: https://github.com/sato-na/guruwake_java
--kotlin version: https://github.com/sato-na/guruwake_kotlin
↓ This is the main subject of this article ↓
--For java
Qualifier Return type Function name(argument, argument, …) {
Function content
return Return value
}
Example)
WhoActivity.java
private void addMember() { //Line 78
EditText memberET = findViewById(R.id.member_et);
ListView memberLV = findViewById(R.id.member_lv);
memberL.add(memberET.getText().toString());
memberET.getEditableText().clear();
ArrayList<String> memberLR = (ArrayList<String>) memberL.clone();
Collections.reverse(memberLR);
ArrayAdapter<String> adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, memberLR);
memberLV.setAdapter(adapter);
}
--For kotlin
fun function name(argument:Mold, argument:Mold, …) 戻り値のMold {
Function content
return Return value
}
Example)
WhoActivity.kt
fun addMember() { //Line 52
memberL.add(member_et.text.toString())
member_et?.text?.clear()
var memverLR = ArrayList<String>(memberL)
memverLR.reverse()
var adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, memverLR)
member_lv.adapter = adapter
}
The writing method is very different, but the information required when defining a function is almost the same.
This time, I defined the function in java and kotlin. Functions with various functions can be defined depending on the type of argument and the type of return value, so I hope to continue to use them frequently.
I will post an article tomorrow, so please keep an eye on me.
Recommended Posts