This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyAdapter : ListAdapter<String, MyAdapter.ViewHolder>(DiffCallBack) { | |
class ViewHolder(private val binding: AdapterItemBinding) : | |
RecyclerView.ViewHolder(binding.root) { | |
fun bind(text: String) { | |
binding.textView.text = text | |
} | |
} | |
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlinx.parcelize.Parcelize | |
import android.os.Parcelable | |
@Parcelize | |
class User(val name: String, val age: Int): Parcelable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
.. | |
id 'kotlin-parcelize' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NonNull | |
public static ActivityMainBinding bind(@NonNull View rootView) { | |
// The body of this method is generated in a way you would not otherwise write. | |
// This is done to optimize the compiled bytecode for size and performance. | |
int id; | |
missingId: { | |
id = R.id.textView; | |
TextView textView = rootView.findViewById(id); | |
if (textView == null) { | |
break missingId; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@NonNull | |
public static ActivityMainBinding inflate(@NonNull LayoutInflater inflater) { | |
return inflate(inflater, null, false); | |
} | |
@NonNull | |
public static ActivityMainBinding inflate(@NonNull LayoutInflater inflater, | |
@Nullable ViewGroup parent, boolean attachToParent) { | |
View root = inflater.inflate(R.layout.activity_main, parent, false); | |
if (attachToParent) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class ActivityMainBinding implements ViewBinding { | |
@NonNull | |
private final ConstraintLayout rootView; | |
@NonNull | |
public final TextView textView; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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/textView" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var _binding: FragmentMainBinding? = null | |
private val binding get() = _binding!! | |
override fun onCreateView( | |
inflater: LayoutInflater, | |
container: ViewGroup?, | |
savedInstanceState: Bundle? | |
): View? { | |
_binding = FragmentMainBinding.inflate(inflater, container, false) | |
return binding.root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
.. | |
buildFeatures { | |
viewBinding true | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = ActivityMainBinding.inflate(layoutInflater) | |
setContentView(binding.root) | |
} |
NewerOlder