Skip to content

Commit 175b55c

Browse files
committed
新增Spinner示例
1 parent fac698a commit 175b55c

File tree

7 files changed

+86
-3
lines changed

7 files changed

+86
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# FastAdapter
2-
一个快速进行适配器编写的库,适用于RecyclerView,ListView,GridView,ViewPager等
2+
一个快速进行适配器编写的库,适用于RecyclerViewListViewGridView、ViewPager、ViewPager2、ExpandableListView、Spinner等
33
可大大减少样板代码,简化Adapter的编写。
44

55
### 引入依赖
66

77
```kotlin
8-
implementation 'com.yhw.library:fastadapter:1.0.0'
8+
implementation 'com.yhw.library:fastadapter:1.0.1'
99
```
1010

1111
### 使用方法

sample/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
android:roundIcon="@mipmap/ic_launcher_round"
1111
android:supportsRtl="true"
1212
android:theme="@style/Theme.FastAdapter">
13-
<activity android:name=".ViewPager2FragmentActivity"></activity>
13+
<activity android:name=".SpinnerActivity"></activity>
14+
<activity android:name=".ViewPager2FragmentActivity" />
1415
<activity android:name=".ViewPager2Activity" />
1516
<activity android:name=".ExpandableListActivity" />
1617
<activity android:name=".ListViewActivity" />

sample/src/main/java/com/yhw/demo/MainActivity.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,9 @@ class MainActivity : AppCompatActivity() {
4040
findViewById<Button>(R.id.btn_viewpager2_fragment).setOnClickListener {
4141
startActivity(Intent(this, ViewPager2FragmentActivity::class.java))
4242
}
43+
44+
findViewById<Button>(R.id.btn_spanner).setOnClickListener {
45+
startActivity(Intent(this, SpinnerActivity::class.java))
46+
}
4347
}
4448
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.yhw.demo
2+
3+
import android.os.Bundle
4+
import android.view.ViewGroup
5+
import androidx.appcompat.app.AppCompatActivity
6+
import androidx.appcompat.widget.AppCompatSpinner
7+
import com.yhw.library.adapter.BaseListGridAdapter
8+
9+
class SpinnerActivity : AppCompatActivity() {
10+
override fun onCreate(savedInstanceState: Bundle?) {
11+
super.onCreate(savedInstanceState)
12+
setContentView(R.layout.activity_spinner)
13+
14+
val spinner = findViewById<AppCompatSpinner>(R.id.spinner)
15+
val dataList = mutableListOf("北京", "重庆", "天津", "上海", "广州", "西安", "石家庄", "呼和浩特", "乌鲁木齐")
16+
spinner.adapter = MyAdapter(dataList)
17+
}
18+
19+
class MyAdapter(dataList: MutableList<String>) : BaseListGridAdapter<String>(dataList) {
20+
override fun getItemLayoutId(): Int {
21+
return R.layout.spinner_item_layout
22+
}
23+
24+
override fun onBindViewItem(
25+
position: Int,
26+
data: String,
27+
parent: ViewGroup?,
28+
holder: ViewHolder
29+
) {
30+
holder.setText(R.id.tv_text, data)
31+
}
32+
33+
}
34+
}

sample/src/main/res/layout/activity_main.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,12 @@
6363
android:textAllCaps="false"
6464
app:layout_constraintTop_toBottomOf="@id/btn_viewpager2" />
6565

66+
<Button
67+
android:id="@+id/btn_spanner"
68+
android:layout_width="match_parent"
69+
android:layout_height="wrap_content"
70+
android:text="Spanner"
71+
android:textAllCaps="false"
72+
app:layout_constraintTop_toBottomOf="@id/btn_viewpager2_fragment" />
73+
6674
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
xmlns:tools="http://schemas.android.com/tools"
5+
android:layout_width="match_parent"
6+
android:layout_height="match_parent"
7+
tools:context=".SpinnerActivity">
8+
9+
<androidx.appcompat.widget.AppCompatSpinner
10+
android:id="@+id/spinner"
11+
android:layout_width="match_parent"
12+
android:layout_height="60dp"
13+
android:layout_margin="20dp"
14+
app:layout_constraintBottom_toBottomOf="parent"
15+
app:layout_constraintLeft_toLeftOf="parent"
16+
app:layout_constraintRight_toRightOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
18+
19+
</androidx.constraintlayout.widget.ConstraintLayout>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:background="?attr/selectableItemBackground"
6+
android:gravity="center_vertical"
7+
android:orientation="horizontal"
8+
android:padding="10dp">
9+
10+
<TextView
11+
android:id="@+id/tv_text"
12+
android:layout_width="match_parent"
13+
android:layout_height="wrap_content"
14+
android:layout_marginStart="10dp"
15+
android:layout_marginLeft="10dp" />
16+
17+
</LinearLayout>

0 commit comments

Comments
 (0)