Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit bcce39c

Browse files
author
evgenii
committed
Added ExpandableListView to Report
1 parent 9532574 commit bcce39c

File tree

3 files changed

+118
-6
lines changed

3 files changed

+118
-6
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/activity/ReportActivity.java

Lines changed: 89 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,40 @@
33
import android.app.Activity;
44
import android.content.Intent;
55
import android.os.Bundle;
6+
import android.util.Log;
7+
import android.util.Pair;
68
import android.view.View;
79
import android.view.ViewTreeObserver;
810
import android.view.Window;
911
import android.widget.Button;
12+
import android.widget.ExpandableListView;
1013
import android.widget.ListView;
11-
import android.widget.TextView;
14+
import android.widget.SimpleExpandableListAdapter;
1215

1316
import com.blogspot.e_kanivets.moneytracker.R;
1417
import com.blogspot.e_kanivets.moneytracker.adapter.ReportItemAdapter;
1518
import com.blogspot.e_kanivets.moneytracker.helper.MTHelper;
19+
import com.blogspot.e_kanivets.moneytracker.model.Record;
1620
import com.blogspot.e_kanivets.moneytracker.model.Report;
1721

22+
import java.util.ArrayList;
23+
import java.util.HashMap;
24+
import java.util.List;
25+
import java.util.Map;
26+
1827
/**
1928
* Created by eugene on 11/09/14.
2029
*/
2130
public class ReportActivity extends Activity {
2231

32+
private static final String TAG = ReportActivity.class.getSimpleName();
33+
private static final String TITLE_PARAM_NAME = "title";
34+
2335
private Activity activity;
36+
private Report report;
2437

2538
private ListView listView;
39+
private ExpandableListView expandableListView;
2640

2741
@Override
2842
protected void onCreate(Bundle savedInstanceState) {
@@ -31,16 +45,19 @@ protected void onCreate(Bundle savedInstanceState) {
3145
setContentView(R.layout.activity_report);
3246

3347
activity = this;
48+
report = new Report(MTHelper.getInstance().getRecords());
3449

35-
Button btnThankAuthor;
50+
initViews();
51+
}
3652

37-
btnThankAuthor = (Button) findViewById(R.id.btn_thank_author);
53+
private void initViews() {
3854
listView = (ListView) findViewById(R.id.listView);
55+
expandableListView = (ExpandableListView) findViewById(R.id.expandableListView);
3956

4057
/*tvTitle.setText("REPORT (" + MTHelper.getInstance().getFirstDay() + " - "
4158
+ MTHelper.getInstance().getLastDay() + ")");*/
4259

43-
btnThankAuthor.setOnClickListener(new View.OnClickListener() {
60+
findViewById(R.id.btn_thank_author).setOnClickListener(new View.OnClickListener() {
4461
@Override
4562
public void onClick(View view) {
4663
Intent intent = new Intent(ReportActivity.this, ThankAuthorActivity.class);
@@ -57,11 +74,77 @@ public void onClick(View view) {
5774

5875
@Override
5976
public void onGlobalLayout() {
60-
if(isFirst) {
77+
if (isFirst) {
6178
isFirst = false;
62-
listView.setSelection(listView.getCount()-1);
79+
listView.setSelection(listView.getCount() - 1);
6380
}
6481
}
6582
});
83+
84+
initExpandableListView();
85+
}
86+
87+
private void initExpandableListView() {
88+
/* List for groups */
89+
List<Map<String, String>> groupData;
90+
91+
/* List for child items */
92+
List<Map<String, String>> childDataItem;
93+
94+
/* List for childDataItems */
95+
List<List<Map<String, String>>> childData;
96+
97+
/* Buffer map for names of values */
98+
Map<String, String> m;
99+
100+
/* Fill the group list */
101+
groupData = new ArrayList<Map<String, String>>();
102+
for (Pair<String, Integer> item : report.getReportList()) {
103+
/* Fill up attribute names for each group */
104+
m = new HashMap<String, String>();
105+
m.put(TITLE_PARAM_NAME, item.first);
106+
107+
groupData.add(m);
108+
}
109+
110+
/* List of attributes of groups for reading */
111+
String groupFrom[] = new String[]{TITLE_PARAM_NAME};
112+
/* List of view IDs for information insertion */
113+
int groupTo[] = new int[]{android.R.id.text1};
114+
115+
/* Create list for childDataItems */
116+
childData = new ArrayList<List<Map<String, String>>>();
117+
118+
for (Map<String, String> group : groupData) {
119+
childDataItem = new ArrayList<Map<String, String>>();
120+
/* Fill up attribute names for each child item */
121+
for (Record record : MTHelper.getInstance().getRecords()) {
122+
if (record.getCategory().equals(group.get(TITLE_PARAM_NAME))) {
123+
Log.d(TAG, record.getCategory());
124+
m = new HashMap<String, String>();
125+
m.put(TITLE_PARAM_NAME, record.getTitle());
126+
childDataItem.add(m);
127+
}
128+
}
129+
130+
/* Add childDataItem to common childData */
131+
childData.add(childDataItem);
132+
}
133+
134+
/* List of attributes of childItems for reading */
135+
String childFrom[] = new String[]{TITLE_PARAM_NAME};
136+
/* List of view IDs for information insertion */
137+
int childTo[] = new int[]{android.R.id.text1};
138+
139+
expandableListView.setAdapter(new SimpleExpandableListAdapter(
140+
activity,
141+
groupData,
142+
android.R.layout.simple_expandable_list_item_1,
143+
groupFrom,
144+
groupTo,
145+
childData,
146+
android.R.layout.simple_list_item_1,
147+
childFrom,
148+
childTo));
66149
}
67150
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.blogspot.e_kanivets.moneytracker.adapter;
2+
3+
import android.content.Context;
4+
import android.widget.SimpleExpandableListAdapter;
5+
6+
import java.util.List;
7+
import java.util.Map;
8+
9+
/**
10+
* Created by evgenii on 12/29/14.
11+
*/
12+
public class ExpandableListReportAdapter extends SimpleExpandableListAdapter {
13+
14+
public ExpandableListReportAdapter(Context context, List<? extends Map<String, ?>> groupData,
15+
int groupLayout, String[] groupFrom, int[] groupTo,
16+
List<? extends List<? extends Map<String, ?>>> childData,
17+
int childLayout, String[] childFrom, int[] childTo) {
18+
super(context, groupData, groupLayout, groupFrom, groupTo, childData, childLayout, childFrom, childTo);
19+
}
20+
21+
22+
}

app/src/main/res/layout/activity_report.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@
5454
android:layout_width="match_parent"
5555
android:layout_height="wrap_content"
5656
android:id="@+id/listView"
57+
android:layout_gravity="center_horizontal"
58+
android:visibility="gone" />
59+
60+
<ExpandableListView
61+
android:layout_width="match_parent"
62+
android:layout_height="wrap_content"
63+
android:id="@+id/expandableListView"
5764
android:layout_gravity="center_horizontal" />
5865

5966
</LinearLayout>

0 commit comments

Comments
 (0)