Reputation: 232
The image shows what I want to accomplish.
In my activity, I would like to have an expandablelistview. Which, when clicked on, will show a list of items (the items in the list will be populated from a database table). Next to every item, I would like to display a minus, a plus and a number. Every time the plus is clicked the number will add one on the displaying number or if the minus is clicked the displaying number will be subtracted by one. I believe you get the general idea of how the items and the "+" and "-" will work.
I've viewed this tutorial: Android Custom View Tutorial (Part 1) – Combining Existing Views Unfortunately, this tutorial only covers the plus and minus part and not the expandable view.
The problem I'm facing is how will I imprint this in Java. I've read that I should combine views, but I'm not exactly sure on how. Am I on the correct path? (In general: I have the design but don't know how to code it)
Upvotes: 0
Views: 853
Reputation: 191
If i understand correctly you only need to create the expandablelistview and the adapter (see here https://www.codeproject.com/Articles/1151814/Android-ExpandablelistView-Tutorial-with-Android-C), then inside getChildView()
inflate the R.layout.child_row
that contains your Custom View (or you can create a layout using native Android widgets, as the example below).
<!-- child_row.xml -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ellipsize="end"
android:singleLine="true"
tools:text="Menu Item 1" />
<Button
android:id="@+id/bt_less"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="-"
android:textColor="@android:color/holo_red_light" />
<TextView
android:layout_width="50dp"
android:layout_height="wrap_content"
android:gravity="center"
tools:text="0" />
<Button
android:id="@+id/bt_more"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:text="+"
android:textColor="@android:color/holo_green_light" />
</LinearLayout>
Upvotes: 2