|
@@ -16,7 +16,7 @@ import java.util.ArrayList;
|
16
|
16
|
|
17
|
17
|
public class ListViewAdapter extends BaseAdapter {
|
18
|
18
|
// Adapter에 추가된 데이터를 저장하기 위한 ArrayList
|
19
|
|
- private ArrayList<ListViewItem> listViewItemList = new ArrayList<ListViewItem>() ;
|
|
19
|
+ private ArrayList<ListViewItem> listViewItemList = new ArrayList<ListViewItem>();
|
20
|
20
|
private ArrayList<ListViewItem> filteredItemList = listViewItemList;
|
21
|
21
|
|
22
|
22
|
// ListViewAdapter의 생성자
|
|
@@ -27,7 +27,7 @@ public class ListViewAdapter extends BaseAdapter {
|
27
|
27
|
// Adapter에 사용되는 데이터의 개수를 리턴. : 필수 구현
|
28
|
28
|
@Override
|
29
|
29
|
public int getCount() {
|
30
|
|
- return filteredItemList.size() ;
|
|
30
|
+ return filteredItemList.size();
|
31
|
31
|
}
|
32
|
32
|
|
33
|
33
|
// position에 위치한 데이터를 화면에 출력하는데 사용될 View를 리턴. : 필수 구현
|
|
@@ -45,18 +45,18 @@ public class ListViewAdapter extends BaseAdapter {
|
45
|
45
|
holder = new ViewHolder();
|
46
|
46
|
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
47
|
47
|
convertView = inflater.inflate(R.layout.activity_list_view_item, parent, false);
|
48
|
|
- holder.editText = (EditText)convertView.findViewById(R.id.editText);
|
|
48
|
+ holder.editText = (EditText) convertView.findViewById(R.id.editText);
|
49
|
49
|
convertView.setTag(holder);
|
50
|
|
- }else{
|
51
|
|
- holder = (ViewHolder)convertView.getTag();
|
|
50
|
+ } else {
|
|
51
|
+ holder = (ViewHolder) convertView.getTag();
|
52
|
52
|
}
|
53
|
53
|
holder.ref = position;
|
54
|
54
|
// Log.d("getView", String.valueOf(position));
|
55
|
55
|
// 화면에 표시될 View(Layout이 inflate된)으로부터 위젯에 대한 참조 획득
|
56
|
|
- TextView descTextView = (TextView) convertView.findViewById(R.id.textView13) ;
|
57
|
|
- TextView valTextView = (TextView) convertView.findViewById(R.id.textView14) ;
|
|
56
|
+ TextView descTextView = (TextView) convertView.findViewById(R.id.textView13);
|
|
57
|
+ TextView valTextView = (TextView) convertView.findViewById(R.id.textView14);
|
58
|
58
|
|
59
|
|
- final EditText valeditText = (EditText) convertView.findViewById(R.id.editText) ;
|
|
59
|
+ final EditText valeditText = (EditText) convertView.findViewById(R.id.editText);
|
60
|
60
|
valeditText.addTextChangedListener(new TextWatcher() {
|
61
|
61
|
@Override
|
62
|
62
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
@@ -70,14 +70,14 @@ public class ListViewAdapter extends BaseAdapter {
|
70
|
70
|
|
71
|
71
|
@Override
|
72
|
72
|
public void afterTextChanged(Editable s) {
|
73
|
|
- Log.d("getView",s.toString() );
|
|
73
|
+ Log.d("getView", s.toString());
|
74
|
74
|
filteredItemList.get(holder.ref).setVal(s.toString());
|
75
|
75
|
|
76
|
76
|
// valeditText.setText(s.toString());
|
77
|
77
|
// valeditText.setText();
|
78
|
78
|
}
|
79
|
79
|
});
|
80
|
|
- EditText valeditText1 = (EditText) convertView.findViewById(R.id.editText1) ;
|
|
80
|
+ EditText valeditText1 = (EditText) convertView.findViewById(R.id.editText1);
|
81
|
81
|
valeditText1.addTextChangedListener(new TextWatcher() {
|
82
|
82
|
@Override
|
83
|
83
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
@@ -96,7 +96,7 @@ public class ListViewAdapter extends BaseAdapter {
|
96
|
96
|
|
97
|
97
|
}
|
98
|
98
|
});
|
99
|
|
- EditText valeditText2 = (EditText) convertView.findViewById(R.id.editText2) ;
|
|
99
|
+ EditText valeditText2 = (EditText) convertView.findViewById(R.id.editText2);
|
100
|
100
|
valeditText2.addTextChangedListener(new TextWatcher() {
|
101
|
101
|
@Override
|
102
|
102
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
@@ -115,22 +115,19 @@ public class ListViewAdapter extends BaseAdapter {
|
115
|
115
|
filteredItemList.get(holder.ref).setVal2(s.toString());
|
116
|
116
|
}
|
117
|
117
|
});
|
118
|
|
- final Button valbutton = (Button) convertView.findViewById(R.id.listView_button) ;
|
|
118
|
+ final Button valbutton = (Button) convertView.findViewById(R.id.listView_button);
|
119
|
119
|
valbutton.setOnClickListener(new Button.OnClickListener() {
|
120
|
120
|
public void onClick(View v) {
|
121
|
|
- if(valbutton.getText() =="ON") {
|
|
121
|
+ if (valbutton.getText() == "ON") {
|
122
|
122
|
valbutton.setText("OFF");
|
123
|
|
- }
|
124
|
|
- else if(valbutton.getText() == "OFF") {
|
|
123
|
+ } else if (valbutton.getText() == "OFF") {
|
125
|
124
|
valbutton.setText("ON");
|
126
|
|
- }
|
127
|
|
- else if (valbutton.getText() == "MANUAL") {
|
|
125
|
+ } else if (valbutton.getText() == "MANUAL") {
|
128
|
126
|
valbutton.setText("AUTO");
|
129
|
|
- }
|
130
|
|
- else if (valbutton.getText() == "AUTO") {
|
|
127
|
+ } else if (valbutton.getText() == "AUTO") {
|
131
|
128
|
valbutton.setText("MANUAL");
|
132
|
129
|
}
|
133
|
|
- // valbutton.setText("OFF");
|
|
130
|
+ // valbutton.setText("OFF");
|
134
|
131
|
}
|
135
|
132
|
});
|
136
|
133
|
// Data Set(listViewItemList)에서 position에 위치한 데이터 참조 획득
|
|
@@ -140,24 +137,25 @@ public class ListViewAdapter extends BaseAdapter {
|
140
|
137
|
valbutton.setVisibility(View.VISIBLE);
|
141
|
138
|
valeditText1.setVisibility(View.VISIBLE);
|
142
|
139
|
valeditText2.setVisibility(View.VISIBLE);
|
|
140
|
+
|
143
|
141
|
// 아이템 내 각 위젯에 데이터 반영
|
144
|
|
- descTextView.setText(listViewItem.getDesc());
|
145
|
|
- if(listViewItem.getMode() == "READ") {
|
|
142
|
+ {
|
|
143
|
+ descTextView.setText(listViewItem.getDesc());
|
|
144
|
+ }
|
|
145
|
+ if (listViewItem.getMode() == "READ") {
|
146
|
146
|
valTextView.setText(listViewItem.getVal());
|
147
|
147
|
valeditText.setVisibility(View.INVISIBLE);
|
148
|
148
|
valeditText1.setVisibility(View.INVISIBLE);
|
149
|
149
|
valeditText2.setVisibility(View.INVISIBLE);
|
150
|
150
|
valbutton.setVisibility(View.INVISIBLE);
|
151
|
151
|
|
152
|
|
- }
|
153
|
|
- else if(listViewItem.getMode() == "EDIT") {
|
|
152
|
+ } else if (listViewItem.getMode() == "EDIT") {
|
154
|
153
|
valTextView.setVisibility(View.INVISIBLE);
|
155
|
154
|
valeditText.setText(listViewItem.getVal());
|
156
|
155
|
valeditText1.setVisibility(View.INVISIBLE);
|
157
|
156
|
valeditText2.setVisibility(View.INVISIBLE);
|
158
|
157
|
valbutton.setVisibility(View.INVISIBLE);
|
159
|
|
- }
|
160
|
|
- else if(listViewItem.getMode() == "EDIT2") {
|
|
158
|
+ } else if (listViewItem.getMode() == "EDIT2") {
|
161
|
159
|
valTextView.setVisibility(View.INVISIBLE);
|
162
|
160
|
valeditText1.setVisibility(View.VISIBLE);
|
163
|
161
|
valeditText2.setVisibility(View.VISIBLE);
|
|
@@ -165,15 +163,14 @@ public class ListViewAdapter extends BaseAdapter {
|
165
|
163
|
valbutton.setVisibility(View.INVISIBLE);
|
166
|
164
|
valeditText1.setText(listViewItem.getVal());
|
167
|
165
|
valeditText2.setText(listViewItem.getVal2());
|
168
|
|
- }
|
169
|
|
- else if(listViewItem.getMode() == "BUTTON") {
|
|
166
|
+ } else if (listViewItem.getMode() == "BUTTON") {
|
170
|
167
|
valTextView.setVisibility(View.INVISIBLE);
|
171
|
168
|
valeditText.setVisibility(View.INVISIBLE);
|
172
|
169
|
valeditText1.setVisibility(View.INVISIBLE);
|
173
|
170
|
valeditText2.setVisibility(View.INVISIBLE);
|
174
|
171
|
valbutton.setVisibility(View.VISIBLE);
|
175
|
172
|
valbutton.setText(listViewItem.getVal());
|
176
|
|
- }else{
|
|
173
|
+ } else {
|
177
|
174
|
valeditText1.setVisibility(View.INVISIBLE);
|
178
|
175
|
valeditText2.setVisibility(View.INVISIBLE);
|
179
|
176
|
valTextView.setVisibility(View.INVISIBLE);
|
|
@@ -181,34 +178,38 @@ public class ListViewAdapter extends BaseAdapter {
|
181
|
178
|
valbutton.setVisibility(View.VISIBLE);
|
182
|
179
|
// valbutton.setText(listViewItem.getVal());
|
183
|
180
|
}
|
184
|
|
-
|
|
181
|
+ Log.d("getView", String.valueOf(getItem(position)) + "Position : " + position);
|
185
|
182
|
// descTextView.setBackgroundColor();
|
186
|
183
|
return convertView;
|
187
|
184
|
}
|
|
185
|
+
|
188
|
186
|
// 지정한 위치(position)에 있는 데이터와 관계된 아이템(row)의 ID를 리턴. : 필수 구현
|
189
|
187
|
@Override
|
190
|
188
|
public long getItemId(int position) {
|
191
|
|
- return position ;
|
|
189
|
+ return position;
|
192
|
190
|
}
|
193
|
191
|
|
194
|
192
|
// 지정한 위치(position)에 있는 데이터 리턴 : 필수 구현
|
195
|
193
|
@Override
|
196
|
194
|
public Object getItem(int position) {
|
197
|
|
- return filteredItemList.get(position) ;
|
|
195
|
+ return filteredItemList.get(position);
|
198
|
196
|
}
|
199
|
|
- public void setItem(String desc,String val,String val2,String mode,int position) {
|
|
197
|
+
|
|
198
|
+ public void setItem(String desc, String val, String val2, String mode, int position) {
|
200
|
199
|
ListViewItem item = new ListViewItem();
|
201
|
200
|
item.setDesc(desc);
|
202
|
201
|
item.setMode(mode);
|
203
|
202
|
item.setVal(val);
|
204
|
203
|
item.setVal2(val2);
|
205
|
|
- filteredItemList.set(position,item) ;
|
|
204
|
+ filteredItemList.set(position, item);
|
206
|
205
|
}
|
|
206
|
+
|
207
|
207
|
public void removeItem(int position) {
|
208
|
208
|
filteredItemList.remove(position);
|
209
|
209
|
}
|
|
210
|
+
|
210
|
211
|
// 아이템 데이터 추가를 위한 함수. 개발자가 원하는대로 작성 가능.
|
211
|
|
- public void addItem(String desc,String val,String val2,String mode) {
|
|
212
|
+ public void addItem(String desc, String val, String val2, String mode) {
|
212
|
213
|
ListViewItem item = new ListViewItem();
|
213
|
214
|
|
214
|
215
|
item.setDesc(desc);
|
|
@@ -219,6 +220,7 @@ public class ListViewAdapter extends BaseAdapter {
|
219
|
220
|
filteredItemList.add(item);
|
220
|
221
|
}
|
221
|
222
|
}
|
|
223
|
+
|
222
|
224
|
class ViewHolder {
|
223
|
225
|
EditText editText;
|
224
|
226
|
EditText editText1;
|