1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
package com.example.surgerylog;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Dictionary;
import java.util.Hashtable;
import java.util.List;
import net.redroid.medlog.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;
public class ViewDataFragment extends Fragment {
/**
* The fragment argument representing the section number for this fragment.
*/
public static final String ARG_SECTION_NUMBER = "section_number";
private MainActivity _activity;
List<String> _viewDataList = new ArrayList<String>();
int _lastSelected;
public ViewDataFragment() {
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// This makes sure that the container activity has implemented
// the callback interface. If not, it throws an exception
try {
_activity = (MainActivity) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString()
+ " must implement OnHeadlineSelectedListener");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// get root view
View rootView = inflater.inflate(R.layout.fragment_view_data,
container, false);
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onActivityCreated(savedInstanceState);
// get list view
ListView listView = ((ListView) getView().findViewById(
R.id.dataBaseListView));
// set list view on click event
listView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// hold last selected
_lastSelected = position;
// prepare the alert box
AlertDialog.Builder _alertbox = new AlertDialog.Builder(
_activity);
MedLogInfo info = _activity.DataBase.get(position);
String infoStr = "#Pro: " + info.ProcessNumber.toString()
+ "\n" + "#Cir: " + info.SurgeryNumber.toString()
+ "\n" + "Data: " + info.GetFormatedDate()
+ "\n" + "Ajud: " + info.FirstAider
+ "\n" + "Anst: " + info.Anesthesia
+ "\n" + "Locl: " + info.Place
+ "\n" + "Tipo: " + info.Type
+ "\n" + "Subt: " + info.SubType
+ "\n" + "Pato: " + info.Pathology
+ "\n" + "Intr: " + info.Intervention
+ "\n" + "Urgn: " + _activity.getString(info.Urgency == true ? R.string.yes_str : R.string.no_str)
+ "\n" + "Nota: " + info.Notes
;
_alertbox.setMessage(infoStr);
_alertbox.setNeutralButton(R.string.ok_str,
new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// nothing to do here
}
});
_alertbox.setNegativeButton(R.string.delete_str,
new DialogInterface.OnClickListener() {
// click listener on the alert box
public void onClick(DialogInterface arg0, int arg1) {
// TODO delete the database entry
_activity.DataBase.remove(_lastSelected);
_activity.SaveMedLogDB();
UpdateListView();
}
});
_alertbox.show();
}
});
// REFRESH BUTTON
Button refreshBtn = (Button) getView().findViewById(R.id.refreshBtn);
refreshBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
UpdateListView();
}
});
}
@Override
public void onResume() {
super.onResume();
UpdateListView();
}
public void UpdateListView() {
// get list data
if (_activity.DataBase != null) {
// remove old entries
_viewDataList.clear();
// add new entries
for (MedLogInfo log : _activity.DataBase) {
_viewDataList.add(log.ProcessNumber.toString());
}
}
// create array adapter
ArrayAdapter<String> adapter = new ArrayAdapter<String>(getView()
.getContext(), android.R.layout.simple_list_item_1,
_viewDataList);
// // sort list values
// adapter.sort(new Comparator<String>() {
// public int compare(String object1, String object2) {
// return object1.compareTo(object2);
// }
// });
// get list view
ListView listView = ((ListView) getView().findViewById(
R.id.dataBaseListView));
// set adapter
listView.setAdapter(adapter);
}
}
|