Skip to content

Commit 67ec49d

Browse files
committed
Add chart index display to SpecialChartAdapter
Introduced a new TextView to show the chart index in each item of the SpecialChartAdapter. Updated the item layout to include an index badge with a custom background and adjusted layout structure for better visual grouping.
1 parent e1f8e05 commit 67ec49d

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

sample/src/main/java/com/github/aachartmodel/aainfographics/demo/basiccontent/SpecialChartAdapter.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class SpecialChartAdapter(
1919
) : RecyclerView.Adapter<SpecialChartAdapter.ViewHolder>() {
2020

2121
class ViewHolder(view: View) : RecyclerView.ViewHolder(view) {
22+
val indexTextView: TextView = view.findViewById(R.id.tv_chart_index)
2223
val nameTextView: TextView = view.findViewById(R.id.tv_chart_name)
2324
val aaChartView: AAChartView = view.findViewById(R.id.aa_chart_view)
2425
}
@@ -30,6 +31,7 @@ class SpecialChartAdapter(
3031

3132
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
3233
val item = chartItems[position]
34+
holder.indexTextView.text = "${position + 1}."
3335
holder.nameTextView.text = item.name
3436
val aaChartModel = getChartModel(item.chartType)
3537
holder.aaChartView.aa_drawChartWithChartModel(aaChartModel)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:shape="oval">
4+
<solid android:color="#2196F3" />
5+
</shape>

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,44 @@
55
android:layout_height="wrap_content"
66
android:padding="8dp">
77

8-
<TextView
9-
android:id="@+id/tv_chart_name"
8+
<LinearLayout
9+
android:id="@+id/ll_chart_header"
1010
android:layout_width="0dp"
1111
android:layout_height="wrap_content"
12-
android:layout_marginBottom="8dp"
13-
android:textSize="16sp"
14-
android:textStyle="bold"
12+
android:orientation="horizontal"
1513
app:layout_constraintEnd_toEndOf="parent"
1614
app:layout_constraintStart_toStartOf="parent"
17-
app:layout_constraintTop_toTopOf="parent" />
15+
app:layout_constraintTop_toTopOf="parent">
16+
17+
<TextView
18+
android:id="@+id/tv_chart_index"
19+
android:layout_width="24dp"
20+
android:layout_height="24dp"
21+
android:layout_marginEnd="8dp"
22+
android:background="@drawable/index_background"
23+
android:gravity="center"
24+
android:padding="2dp"
25+
android:textColor="@android:color/white"
26+
android:textSize="12sp"
27+
android:textStyle="bold" />
28+
29+
<TextView
30+
android:id="@+id/tv_chart_name"
31+
android:layout_width="0dp"
32+
android:layout_height="wrap_content"
33+
android:layout_weight="1"
34+
android:textSize="16sp"
35+
android:textStyle="bold" />
36+
</LinearLayout>
1837

1938
<com.github.aachartmodel.aainfographics.aachartcreator.AAChartView
2039
android:id="@+id/aa_chart_view"
2140
android:layout_width="0dp"
2241
android:layout_height="300dp"
42+
android:layout_marginTop="8dp"
2343
app:layout_constraintBottom_toBottomOf="parent"
2444
app:layout_constraintEnd_toEndOf="parent"
2545
app:layout_constraintStart_toStartOf="parent"
26-
app:layout_constraintTop_toBottomOf="@id/tv_chart_name" />
46+
app:layout_constraintTop_toBottomOf="@id/ll_chart_header" />
2747

2848
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)