質問編集履歴
1
Adapterクラスのコードを追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -44,6 +44,320 @@
|
|
44
44
|
|
45
45
|
|
46
46
|
|
47
|
+
以下に、Adapterのソースコードを記載させて頂きます。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
```ここに言語を入力
|
52
|
+
|
53
|
+
namespace SampleArticleMemberApp.Droid
|
54
|
+
|
55
|
+
{
|
56
|
+
|
57
|
+
public class ArticleListItemAdapter : BaseAdapter<ArticleListItem>
|
58
|
+
|
59
|
+
{
|
60
|
+
|
61
|
+
public List<ArticleListItem> items;
|
62
|
+
|
63
|
+
public Activity context;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
/**
|
68
|
+
|
69
|
+
* コンストラクタ
|
70
|
+
|
71
|
+
*/
|
72
|
+
|
73
|
+
public ArticleListItemAdapter(Activity context, List<ArticleListItem> items)
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "ArticleListItemAdapter", "-----START-----");
|
78
|
+
|
79
|
+
this.context = context;
|
80
|
+
|
81
|
+
this.items = items;
|
82
|
+
|
83
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "ArticleListItemAdapter", "-----END-----");
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
/**
|
90
|
+
|
91
|
+
* クリック処理
|
92
|
+
|
93
|
+
*/
|
94
|
+
|
95
|
+
public override long GetItemId(int position)
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "GetItemId", "-----START-----");
|
100
|
+
|
101
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "GetItemId", "-----END-----");
|
102
|
+
|
103
|
+
return position;
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
public override ArticleListItem this[int position]
|
110
|
+
|
111
|
+
{
|
112
|
+
|
113
|
+
get { return items[position]; }
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
public override int Count
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
get { return items.Count; }
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
public override View GetView(int position, View convertView, ViewGroup parent)
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "GetView", "-----START-----");
|
134
|
+
|
135
|
+
var item = items[position];
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
View view = convertView;
|
140
|
+
|
141
|
+
if (view == null){
|
142
|
+
|
143
|
+
view = context.LayoutInflater.Inflate(Resource.Layout.ArticleListViewItem, null);
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
// BaseAdapter<T>の対応するプロパティを割り当て
|
150
|
+
|
151
|
+
view.FindViewById<TextView>(Resource.Id.articleItemDate).Text = item.date;
|
152
|
+
|
153
|
+
view.FindViewById<TextView>(Resource.Id.articleItemTitle).Text = item.title;
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
Debug.Log(Debug.DEBUG_LEVEL_INFO, "GetView", item.title);
|
158
|
+
|
159
|
+
Debug.Log(Debug.DEBUG_LEVEL_INFO, "GetView", item.url);
|
160
|
+
|
161
|
+
Debug.Log(Debug.DEBUG_LEVEL_INFO, "GetView", item.thumbUrl);
|
162
|
+
|
163
|
+
Debug.Log(Debug.DEBUG_LEVEL_INFO, "GetView", "readable: " +item.readable.ToString());
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
if(item.thumbUrl != ""){
|
168
|
+
|
169
|
+
Debug.Log(Debug.DEBUG_LEVEL_INFO, "GetView", "画像を読み込みます");
|
170
|
+
|
171
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).SetImageResource(Resource.Mipmap.def_thumb);
|
172
|
+
|
173
|
+
SetThumb(view, position);
|
174
|
+
|
175
|
+
//var image = GetImageBitmapFromUrl(item.thumbUrl);
|
176
|
+
|
177
|
+
//view.FindViewById<ImageView>(Resource.Id.articleItemThumb).SetImageBitmap(image);
|
178
|
+
|
179
|
+
}
|
180
|
+
|
181
|
+
else{
|
182
|
+
|
183
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).SetImageResource(Resource.Mipmap.def_thumb);
|
184
|
+
|
185
|
+
}
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
//読み込み不可能ならば、背景色を変える
|
190
|
+
|
191
|
+
if(!item.readable){
|
192
|
+
|
193
|
+
view.SetBackgroundColor(Color.DarkGray);
|
194
|
+
|
195
|
+
view.FindViewById<TextView>(Resource.Id.articleItemDate).SetTextColor(Color.GhostWhite);
|
196
|
+
|
197
|
+
view.FindViewById<TextView>(Resource.Id.articleItemDate).Alpha = 0.4f;
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
view.FindViewById<TextView>(Resource.Id.articleItemTitle).SetTextColor(Color.GhostWhite);
|
202
|
+
|
203
|
+
view.FindViewById<TextView>(Resource.Id.articleItemTitle).Alpha = 0.4f;
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).Alpha = 0.4f;
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
else{
|
212
|
+
|
213
|
+
view.SetBackgroundColor(Color.GhostWhite);
|
214
|
+
|
215
|
+
view.FindViewById<TextView>(Resource.Id.articleItemDate).SetTextColor(Color.Black);
|
216
|
+
|
217
|
+
view.FindViewById<TextView>(Resource.Id.articleItemDate).Alpha = 1.0f;
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
view.FindViewById<TextView>(Resource.Id.articleItemTitle).SetTextColor(Color.Black);
|
222
|
+
|
223
|
+
view.FindViewById<TextView>(Resource.Id.articleItemTitle).Alpha = 1.0f;
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).Alpha = 1.0f;
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
Debug.Log(Debug.DEBUG_LEVEL_VERBOSE, "GetView", "-----END-----");
|
236
|
+
|
237
|
+
return view;
|
238
|
+
|
239
|
+
}
|
240
|
+
|
241
|
+
|
242
|
+
|
243
|
+
/**
|
244
|
+
|
245
|
+
* URLから、Bitmap生成
|
246
|
+
|
247
|
+
*/
|
248
|
+
|
249
|
+
private async Task<Bitmap> GetImageBitmapFromUrl(string url)
|
250
|
+
|
251
|
+
{
|
252
|
+
|
253
|
+
Bitmap imageBitmap = null;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
try{
|
258
|
+
|
259
|
+
using (var webClient = new WebClient())
|
260
|
+
|
261
|
+
{
|
262
|
+
|
263
|
+
var imageBytes = webClient.DownloadData(url);
|
264
|
+
|
265
|
+
if (imageBytes != null && imageBytes.Length > 0)
|
266
|
+
|
267
|
+
{
|
268
|
+
|
269
|
+
imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
}
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
}
|
278
|
+
|
279
|
+
catch(Exception e)
|
280
|
+
|
281
|
+
{
|
282
|
+
|
283
|
+
Debug.Log(Debug.DEBUG_LEVEL_ERROR, "GetImageBitmapFromUrl", "e: " +e);
|
284
|
+
|
285
|
+
}
|
286
|
+
|
287
|
+
return imageBitmap;
|
288
|
+
|
289
|
+
}
|
290
|
+
|
291
|
+
|
292
|
+
|
293
|
+
private async void SetThumb(View view, int position)
|
294
|
+
|
295
|
+
{
|
296
|
+
|
297
|
+
var item = items[position];
|
298
|
+
|
299
|
+
if(items[position].bitmap == null)
|
300
|
+
|
301
|
+
{
|
302
|
+
|
303
|
+
ImageView imageView = view.FindViewById<ImageView>(Resource.Id.articleItemThumb);
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
Debug.Log(Debug.DEBUG_LEVEL_ERROR, "GetImageBitmapFromUrl", "imgvW: " + imageView.Width);
|
308
|
+
|
309
|
+
Debug.Log(Debug.DEBUG_LEVEL_ERROR, "GetImageBitmapFromUrl", "imgvH: " + imageView.Height);
|
310
|
+
|
311
|
+
if(0 < imageView.Width && 0 < imageView.Height){
|
312
|
+
|
313
|
+
Bitmap bmp = await GetImageBitmapFromUrl(item.thumbUrl);
|
314
|
+
|
315
|
+
int bmpH = (int)((float)imageView.Width / (float)bmp.Width *(float)bmp.Height);
|
316
|
+
|
317
|
+
|
318
|
+
|
319
|
+
int scale = Math.Max(imageView.Width, bmpH);
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
bmp = Bitmap.CreateScaledBitmap(bmp, imageView.Width, bmpH, false);
|
324
|
+
|
325
|
+
items[position].bitmap = await GetImageBitmapFromUrl(item.thumbUrl);
|
326
|
+
|
327
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).SetImageBitmap(items[position].bitmap);
|
328
|
+
|
329
|
+
Debug.Log(Debug.DEBUG_LEVEL_ERROR, "GetImageBitmapFromUrl", "bmpW: " + bmp.Width);
|
330
|
+
|
331
|
+
Debug.Log(Debug.DEBUG_LEVEL_ERROR, "GetImageBitmapFromUrl", "bmpH: " + bmp.Height);
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
bmp.Recycle();
|
336
|
+
|
337
|
+
bmp = null;
|
338
|
+
|
339
|
+
}
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
else
|
344
|
+
|
345
|
+
{
|
346
|
+
|
347
|
+
view.FindViewById<ImageView>(Resource.Id.articleItemThumb).SetImageBitmap(items[position].bitmap);
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
}
|
354
|
+
|
355
|
+
}
|
356
|
+
|
357
|
+
```
|
358
|
+
|
359
|
+
|
360
|
+
|
47
361
|
|
48
362
|
|
49
363
|
以上です。
|