質問編集履歴

2

追加

2019/02/02 18:03

投稿

maikel
maikel

スコア61

test CHANGED
File without changes
test CHANGED
@@ -10,18 +10,26 @@
10
10
 
11
11
 
12
12
 
13
- 全てのページのプログラムを載せるとなると、多すぎて見づらくなりそうなので、それ以外に必要なページ、プログラム等があれば載せますので教えて欲しいです。
13
+ 全てのページのプログラムを載せるとなると、多すぎて見づらくなりそうなので、それ以外に必要なページ、プログラム等があれば載せますので教えて欲しいです。要望があり追加しました。
14
-
15
-
16
-
14
+
15
+
16
+
17
- ページのプログラムです。
17
+ 画像のページのプログラムです。
18
-
18
+
19
- ```Java
19
+ ```java
20
20
 
21
21
  package com.websarva.wings.amdrpod.udemyandroid11_1;
22
22
 
23
23
 
24
24
 
25
+ import android.content.res.ColorStateList;
26
+
27
+ import android.graphics.Bitmap;
28
+
29
+ import android.graphics.Color;
30
+
31
+ import android.graphics.drawable.BitmapDrawable;
32
+
25
33
  import android.os.Bundle;
26
34
 
27
35
  import android.support.design.widget.CollapsingToolbarLayout;
@@ -34,6 +42,8 @@
34
42
 
35
43
  import android.support.v7.app.AppCompatActivity;
36
44
 
45
+ import android.support.v7.graphics.Palette;
46
+
37
47
  import android.support.v7.widget.Toolbar;
38
48
 
39
49
  import android.view.View;
@@ -104,9 +114,11 @@
104
114
 
105
115
 
106
116
 
107
- NestedScrollView scrollView =
117
+ //ScroollView呼び出し
108
-
118
+
109
- (NestedScrollView) findViewById(R.id.scroll);
119
+ NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scrollView); //重大なエラーあり
120
+
121
+ // content_showのスクロールビューと同じにする。同じようなR値が沢山あった為エラーにつながった。
110
122
 
111
123
 
112
124
 
@@ -114,9 +126,9 @@
114
126
 
115
127
  if(getIntent() != null){
116
128
 
117
- long id = getIntent().getLongExtra("ID",-1);
129
+ long mid = getIntent().getLongExtra("id",-1);
118
-
130
+
119
- Schedule sc = mRealm.where(Schedule.class).equalTo("id",id).findFirst();
131
+ Schedule sc = mRealm.where(Schedule.class).equalTo("id",mid).findFirst();
120
132
 
121
133
 
122
134
 
@@ -130,25 +142,269 @@
130
142
 
131
143
  detail.setText(sc.detail);
132
144
 
133
- toolbarImage.setImageResource(images[(int)id %3]);
145
+ toolbarImage.setImageResource(images[(int)mid %3]);
146
+
147
+
148
+
149
+
150
+
134
-
151
+ //Bitmap取得
152
+
153
+ Bitmap bitmap =((BitmapDrawable)toolbarImage.getDrawable()).getBitmap();
154
+
155
+ Palette palette = Palette.from(bitmap).generate();
156
+
157
+
158
+
159
+ //パレットから色を取得する
160
+
161
+ int titleColor = palette.getLightVibrantColor(Color.WHITE);
162
+
163
+ int bodyColor = palette.getDarkMutedColor(Color.BLACK);
164
+
165
+ int scrimColor = palette.getMutedColor(Color.DKGRAY);
166
+
167
+ int iconColor =palette.getVibrantColor(Color.LTGRAY);
168
+
169
+
170
+
171
+ layout.setExpandedTitleColor(titleColor); //eee
172
+
173
+ layout.setContentScrimColor(scrimColor); //画像背景
174
+
175
+ scrollView.setBackgroundColor(bodyColor); //本文背景
176
+
177
+ detail.setTextColor(titleColor); //本文文字
178
+
179
+ fab.setBackgroundTintList(ColorStateList.valueOf(iconColor)); //Floatingbuttonのtintカラー
180
+
181
+ }}
182
+
183
+ @Override
184
+
185
+ protected void onDestroy() {
186
+
187
+ super.onDestroy();
188
+
189
+ mRealm.close();
190
+
135
- }
191
+ }
136
-
192
+
137
- }
193
+ }
194
+
195
+
196
+
197
+ ```
198
+
199
+
200
+
201
+ ListViewが表示されるMainのプログラム
202
+
203
+ ```java
204
+
205
+ package com.websarva.wings.amdrpod.udemyandroid11_1;
206
+
207
+
208
+
209
+ import android.content.Intent;
210
+
211
+ import android.os.Bundle;
212
+
213
+ import android.support.design.widget.FloatingActionButton;
214
+
215
+ import android.support.design.widget.Snackbar;
216
+
217
+ import android.support.v7.app.AppCompatActivity;
218
+
219
+ import android.view.View;
220
+
221
+ import android.widget.AdapterView;
222
+
223
+ import android.widget.Button;
224
+
225
+ import android.widget.ListView;
226
+
227
+
228
+
229
+ import java.util.Date;
230
+
231
+
232
+
233
+ import io.realm.Realm;
234
+
235
+ import io.realm.RealmResults;
236
+
237
+
238
+
239
+ public class MainActivity extends AppCompatActivity {
240
+
241
+ private Realm mrealm;
242
+
243
+ private ListView list;
138
244
 
139
245
 
140
246
 
141
247
  @Override
142
248
 
249
+ protected void onCreate(Bundle savedInstanceState) {
250
+
251
+ super.onCreate(savedInstanceState);
252
+
253
+ setContentView(R.layout.activity_main);
254
+
255
+
256
+
257
+ mrealm = Realm.getDefaultInstance();
258
+
259
+ list = (ListView) findViewById(R.id.list);
260
+
261
+ RealmResults<Schedule> schedules = mrealm.where(Schedule.class).findAll();
262
+
263
+ ScheduleAdapter adapter = new ScheduleAdapter(schedules);
264
+
265
+
266
+
267
+ list.setAdapter(adapter);
268
+
269
+
270
+
271
+ Button dbTest = (Button) findViewById(R.id.dbtestbutton);
272
+
273
+ dbTest.setOnClickListener(new View.OnClickListener() {
274
+
275
+ @Override
276
+
277
+ public void onClick(View v) {
278
+
279
+ Intent intent = new Intent(MainActivity.this, RealmTestActivity.class);
280
+
281
+ startActivity(intent);
282
+
283
+ }
284
+
285
+ });
286
+
287
+ FloatingActionButton add = (FloatingActionButton) findViewById(R.id.add);
288
+
289
+ add.setOnClickListener(new View.OnClickListener() {
290
+
291
+ //app:srcComatにエラーがついているが問題なく動くためスルー
292
+
293
+ @Override
294
+
295
+ public void onClick(View v) {
296
+
297
+ final long[] newId = new long[1];
298
+
299
+ mrealm.executeTransaction(new Realm.Transaction() {
300
+
301
+ @Override
302
+
303
+ public void execute(Realm realm) {
304
+
305
+ Number num = realm.where(Schedule.class).max("id");
306
+
307
+ newId[0] = 0;
308
+
309
+ if (num != null) {
310
+
311
+ newId[0] = num.longValue() + 1;
312
+
313
+ }
314
+
315
+ Schedule sc = realm.createObject(Schedule.class, newId[0]);
316
+
317
+ sc.date = new Date();
318
+
319
+ sc.title = "";
320
+
321
+ sc.detail = "";
322
+
323
+ }
324
+
325
+ });
326
+
327
+ Intent i = new Intent(MainActivity.this, inputActivity.class);
328
+
329
+ i.putExtra("id", newId[0]);
330
+
331
+ startActivity(i);
332
+
333
+ }
334
+
335
+ });
336
+
337
+ list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
338
+
339
+ @Override
340
+
341
+ public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
342
+
343
+ ScheduleAdapter adapter = (ScheduleAdapter) list.getAdapter();
344
+
345
+ Schedule sc = adapter.getItem(position);
346
+
347
+ Intent i = new Intent(MainActivity.this, ShowActivity.class);
348
+
349
+ i.putExtra("id", sc.id);
350
+
351
+ //でかいミス発生!そしててこずった!putExtraのnameはgetExtraと揃えること。大文字小文字まできっちりと。
352
+
353
+ startActivity(i);
354
+
355
+ }
356
+
357
+ });
358
+
359
+ list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
360
+
361
+ @Override
362
+
363
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
364
+
365
+ ScheduleAdapter adapter = (ScheduleAdapter) list.getAdapter();
366
+
367
+ final Schedule sc = adapter.getItem(position);//データベースからposition取得。select文の代わりになる
368
+
369
+ mrealm.executeTransaction(new Realm.Transaction() {
370
+
371
+ @Override
372
+
373
+ public void execute(Realm realm) {
374
+
375
+ sc.deleteFromRealm();
376
+
377
+ }
378
+
379
+ });
380
+
381
+ Snackbar.make(view,"削除しました",Snackbar.LENGTH_LONG)
382
+
383
+ .setAction("OK", new View.OnClickListener() { //スナックバーはアクションを追加できる
384
+
385
+ @Override
386
+
387
+ public void onClick(View v) {
388
+
389
+ Snackbar.make(v,"OKが押された時の処理",Snackbar.LENGTH_SHORT).show();
390
+
391
+ }})
392
+
393
+ .show();
394
+
395
+ return true;
396
+
397
+ }});}
398
+
399
+
400
+
401
+ @Override
402
+
143
- protected void onDestroy() {
403
+ protected void onDestroy() {
144
-
404
+
145
- super.onDestroy();
405
+ super.onDestroy();
146
-
406
+
147
- mRealm.close();
407
+ mrealm.close();}}
148
-
149
- }
150
-
151
- }
152
408
 
153
409
 
154
410
 

1

追記

2019/02/02 18:03

投稿

maikel
maikel

スコア61

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- 同じプログラムで私だけが、どうも数式みたいなのが表示されます。
5
+ 同じプログラムで私だけが、どうも数式みたいなのが表示されます。何らかの設定のミスかなと疑っている次第なのですが。
6
6
 
7
7
 
8
8