-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
82 additions
and
7 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package k.lhl.adapter | ||
|
||
import android.content.Context | ||
import android.util.SparseArray | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.widget.BaseAdapter | ||
|
||
class MultiAdapter<T>(private val context: Context?, private val data: List<Pair<Int, T>>, private val layoutId: SparseArray<Int>, private val bindView: (View, T, Int, Int) -> Unit) : BaseAdapter() { | ||
|
||
override fun getView(position: Int, convertView: View?, parent: ViewGroup?): View { | ||
val view = convertView ?: LayoutInflater.from(context).inflate(layoutId[data[position].first], parent, false) | ||
bindView(view, data[position].second, data[position].first, position) | ||
return view | ||
} | ||
|
||
override fun getItemViewType(position: Int): Int = data[position].first | ||
|
||
override fun getViewTypeCount(): Int = layoutId.size() | ||
|
||
override fun getItem(position: Int): T = data[position].second | ||
|
||
override fun getItemId(position: Int) = position.toLong() | ||
|
||
override fun getCount(): Int = data.size | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:gravity="center_vertical" | ||
android:orientation="horizontal" | ||
android:padding="16dp"> | ||
|
||
|
||
<Button | ||
android:id="@+id/btn" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_marginLeft="16dp" | ||
android:text="测试2" /> | ||
|
||
<TextView | ||
android:id="@+id/tvNum" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" /> | ||
|
||
</LinearLayout> |