Sunday, August 18, 2019

RecyclerView dan CardView pada Kotlin

Centang Include Kotlin Support kemudian Klik next
Api minimun api (di sini saya menggunakan minimum api 19) kemudian klik next
pilih Empty Activity kemudian klik next
dan terakhir klik finish dan tunggu sampai build gradle nya kelar.
implementation 'com.android.support:recyclerview-v7:27.1.1'
implementation 'com.android.support:cardview-v7:27.1.1'
android:id="@+id/mRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
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">
android:id="@+id/mRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
klik next kemudian finish
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
android:id="@+id/imgList"
android:src="@drawable/ic_android_black_24dp"
android:layout_width="70dp"
android:layout_height="70dp" />
android:id="@+id/lbList"
android:textStyle="bold"
android:text="@string/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="17dp"/>
xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/cardList"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
android:id="@+id/imgList"
android:src="@drawable/ic_android_black_24dp"
android:layout_width="70dp"
android:layout_height="70dp" />
android:id="@+id/lbList"
android:textStyle="bold"
android:text="@string/app_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="17dp"/>



data class Users (val name:String?)
class Adapter(private val list:ArrayList) : RecyclerView.Adapter(){}
class Holder(val view: View) : RecyclerView.ViewHolder(view)
import kotlinx.android.synthetic.main.list.view.*
return Holder(LayoutInflater.from(parent.context).inflate(R.layout.list,parent,false))
holder.view.lbList.text = list?.get(position)?.name
override fun getItemCount(): Int = list?.size
package erthru.imprecyclerviewandcardviewkotlin
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import kotlinx.android.synthetic.main.list.view.*
class Adapter(private val list:ArrayList) : RecyclerView.Adapter(){
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): Holder {
return Holder(LayoutInflater.from(parent.context).inflate(R.layout.list,parent,false))
}
override fun getItemCount(): Int = list?.size
override fun onBindViewHolder(holder: Holder, position: Int) {
holder.view.lbList.text = list?.get(position)?.name
}
class Holder(val view: View) : RecyclerView.ViewHolder(view)
}
val list = ArrayList()
val listUsers = arrayOf(
"Google",
"Apple",
"Microsoft",
"Asus",
"Zenpone",
"Acer"
)
import kotlinx.android.synthetic.main.activity_main.*
mRecyclerView.setHasFixedSize(true)
mRecyclerView.layoutManager = LinearLayoutManager(this)
for (i in 0 until listUsers.size){
list.add(Users(listUsers.get(i)))
if(listUsers.size - 1 == i){
// init adapter yang telah dibuat tadi
val adapter = Adapter(list)
adapter.notifyDataSetChanged()
//tampilkan data dalam recycler view
mRecyclerView.adapter = adapter
}
}
package erthru.imprecyclerviewandcardviewkotlin
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.widget.LinearLayout
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
val list = ArrayList()
val listUsers = arrayOf(
"Google",
"Apple",
"Microsoft",
"Asus",
"Zenpone",
"Acer"
)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mRecyclerView.setHasFixedSize(true)
mRecyclerView.layoutManager = LinearLayoutManager(this)
for (i in 0 until listUsers.size){
list.add(Users(listUsers.get(i)))
if(listUsers.size - 1 == i){
// init adapter yang telah dibuat tadi
val adapter = Adapter(list)
adapter.notifyDataSetChanged()
//tampilkan data dalam recycler view
mRecyclerView.adapter = adapter
}
}
}
}

Memunculkan Simbol & Emoji Pada OS Mac

  Memunculkan Simbol & Emoji  1. Buka aplikasi Pages / Notes pada Macbook. 2. Klik pada Menubar Edit --> Pilih Emoji and Symbols a...