199
CHAPTER 9: User Interface
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_marginRight="8dip"
android:contentDescription="TODO"
android:src="@android:drawable/star_big_on" />
android:id="@+id/secondLine"
android:layout_width="fill_parent"
android:layout_height="26dip"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="@id/icon"
android:singleLine="true"
android:text="Description"
android:textSize="12sp" />
android:id="@+id/firstLine"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/secondLine"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignWithParentIfMissing="true"
android:layout_toRightOf="@id/icon"
android:gravity="center_vertical"
android:text="Example application"
android:textSize="16sp" />
As stated earlier, you could also omit this step and define an item’s layout solely from inside
the code! Next we provide an adapter. In Kotlin this could be as easy as follows:
class MyAdapter(val myDataset:Array) :
RecyclerView.Adapter
() {
companion object {
class ViewHolder(val v:RelativeLayout) :
RecyclerView.ViewHolder(v)
}
override
fun onCreateViewHolder(parent:ViewGroup,
viewType:Int) : ViewHolder {
val v = LayoutInflater.from(parent.context)
.inflate(R.layout.item, parent, false)
as RelativeLayout
return ViewHolder(v)
}
Do'stlaringiz bilan baham: |