質問編集履歴
2
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,18 +4,23 @@
|
|
4
4
|
|
5
5
|

|
6
6
|
|
7
|
-
全てのページのプログラムを載せるとなると、多すぎて見づらくなりそうなので、それ以外に必要なページ、プログラム等があれば載せますので教えて欲しいです。
|
7
|
+
全てのページのプログラムを載せるとなると、多すぎて見づらくなりそうなので、それ以外に必要なページ、プログラム等があれば載せますので教えて欲しいです。要望があり追加しました。
|
8
8
|
|
9
|
-
ページのプログラムです。
|
9
|
+
画像のページのプログラムです。
|
10
|
-
```
|
10
|
+
```java
|
11
11
|
package com.websarva.wings.amdrpod.udemyandroid11_1;
|
12
12
|
|
13
|
+
import android.content.res.ColorStateList;
|
14
|
+
import android.graphics.Bitmap;
|
15
|
+
import android.graphics.Color;
|
16
|
+
import android.graphics.drawable.BitmapDrawable;
|
13
17
|
import android.os.Bundle;
|
14
18
|
import android.support.design.widget.CollapsingToolbarLayout;
|
15
19
|
import android.support.design.widget.FloatingActionButton;
|
16
20
|
import android.support.design.widget.Snackbar;
|
17
21
|
import android.support.v4.widget.NestedScrollView;
|
18
22
|
import android.support.v7.app.AppCompatActivity;
|
23
|
+
import android.support.v7.graphics.Palette;
|
19
24
|
import android.support.v7.widget.Toolbar;
|
20
25
|
import android.view.View;
|
21
26
|
import android.widget.ImageView;
|
@@ -51,28 +56,151 @@
|
|
51
56
|
TextView detail = (TextView)findViewById(R.id.detail);
|
52
57
|
CollapsingToolbarLayout layout =(CollapsingToolbarLayout)findViewById(R.id.toolbar_layout);
|
53
58
|
|
54
|
-
|
59
|
+
//ScroollView呼び出し
|
55
|
-
|
60
|
+
NestedScrollView scrollView = (NestedScrollView) findViewById(R.id.scrollView); //重大なエラーあり
|
61
|
+
// content_showのスクロールビューと同じにする。同じようなR値が沢山あった為エラーにつながった。
|
56
62
|
|
57
63
|
|
58
64
|
if(getIntent() != null){
|
59
|
-
long
|
65
|
+
long mid = getIntent().getLongExtra("id",-1);
|
60
|
-
Schedule sc = mRealm.where(Schedule.class).equalTo("id",
|
66
|
+
Schedule sc = mRealm.where(Schedule.class).equalTo("id",mid).findFirst();
|
61
67
|
|
62
68
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
|
63
69
|
String format =sdf.format(sc.date);
|
64
70
|
date.setText(format);
|
65
71
|
layout.setTitle(sc.title);
|
66
72
|
detail.setText(sc.detail);
|
67
|
-
toolbarImage.setImageResource(images[(int)
|
73
|
+
toolbarImage.setImageResource(images[(int)mid %3]);
|
68
|
-
}
|
69
|
-
}
|
70
74
|
|
75
|
+
|
76
|
+
//Bitmap取得
|
77
|
+
Bitmap bitmap =((BitmapDrawable)toolbarImage.getDrawable()).getBitmap();
|
78
|
+
Palette palette = Palette.from(bitmap).generate();
|
79
|
+
|
80
|
+
//パレットから色を取得する
|
81
|
+
int titleColor = palette.getLightVibrantColor(Color.WHITE);
|
82
|
+
int bodyColor = palette.getDarkMutedColor(Color.BLACK);
|
83
|
+
int scrimColor = palette.getMutedColor(Color.DKGRAY);
|
84
|
+
int iconColor =palette.getVibrantColor(Color.LTGRAY);
|
85
|
+
|
86
|
+
layout.setExpandedTitleColor(titleColor); //eee
|
87
|
+
layout.setContentScrimColor(scrimColor); //画像背景
|
88
|
+
scrollView.setBackgroundColor(bodyColor); //本文背景
|
89
|
+
detail.setTextColor(titleColor); //本文文字
|
90
|
+
fab.setBackgroundTintList(ColorStateList.valueOf(iconColor)); //Floatingbuttonのtintカラー
|
91
|
+
}}
|
71
|
-
|
92
|
+
@Override
|
72
|
-
|
93
|
+
protected void onDestroy() {
|
73
|
-
|
94
|
+
super.onDestroy();
|
74
|
-
|
95
|
+
mRealm.close();
|
75
|
-
}
|
76
96
|
}
|
97
|
+
}
|
77
98
|
|
99
|
+
```
|
100
|
+
|
101
|
+
ListViewが表示されるMainのプログラム
|
102
|
+
```java
|
103
|
+
package com.websarva.wings.amdrpod.udemyandroid11_1;
|
104
|
+
|
105
|
+
import android.content.Intent;
|
106
|
+
import android.os.Bundle;
|
107
|
+
import android.support.design.widget.FloatingActionButton;
|
108
|
+
import android.support.design.widget.Snackbar;
|
109
|
+
import android.support.v7.app.AppCompatActivity;
|
110
|
+
import android.view.View;
|
111
|
+
import android.widget.AdapterView;
|
112
|
+
import android.widget.Button;
|
113
|
+
import android.widget.ListView;
|
114
|
+
|
115
|
+
import java.util.Date;
|
116
|
+
|
117
|
+
import io.realm.Realm;
|
118
|
+
import io.realm.RealmResults;
|
119
|
+
|
120
|
+
public class MainActivity extends AppCompatActivity {
|
121
|
+
private Realm mrealm;
|
122
|
+
private ListView list;
|
123
|
+
|
124
|
+
@Override
|
125
|
+
protected void onCreate(Bundle savedInstanceState) {
|
126
|
+
super.onCreate(savedInstanceState);
|
127
|
+
setContentView(R.layout.activity_main);
|
128
|
+
|
129
|
+
mrealm = Realm.getDefaultInstance();
|
130
|
+
list = (ListView) findViewById(R.id.list);
|
131
|
+
RealmResults<Schedule> schedules = mrealm.where(Schedule.class).findAll();
|
132
|
+
ScheduleAdapter adapter = new ScheduleAdapter(schedules);
|
133
|
+
|
134
|
+
list.setAdapter(adapter);
|
135
|
+
|
136
|
+
Button dbTest = (Button) findViewById(R.id.dbtestbutton);
|
137
|
+
dbTest.setOnClickListener(new View.OnClickListener() {
|
138
|
+
@Override
|
139
|
+
public void onClick(View v) {
|
140
|
+
Intent intent = new Intent(MainActivity.this, RealmTestActivity.class);
|
141
|
+
startActivity(intent);
|
142
|
+
}
|
143
|
+
});
|
144
|
+
FloatingActionButton add = (FloatingActionButton) findViewById(R.id.add);
|
145
|
+
add.setOnClickListener(new View.OnClickListener() {
|
146
|
+
//app:srcComatにエラーがついているが問題なく動くためスルー
|
147
|
+
@Override
|
148
|
+
public void onClick(View v) {
|
149
|
+
final long[] newId = new long[1];
|
150
|
+
mrealm.executeTransaction(new Realm.Transaction() {
|
151
|
+
@Override
|
152
|
+
public void execute(Realm realm) {
|
153
|
+
Number num = realm.where(Schedule.class).max("id");
|
154
|
+
newId[0] = 0;
|
155
|
+
if (num != null) {
|
156
|
+
newId[0] = num.longValue() + 1;
|
157
|
+
}
|
158
|
+
Schedule sc = realm.createObject(Schedule.class, newId[0]);
|
159
|
+
sc.date = new Date();
|
160
|
+
sc.title = "";
|
161
|
+
sc.detail = "";
|
162
|
+
}
|
163
|
+
});
|
164
|
+
Intent i = new Intent(MainActivity.this, inputActivity.class);
|
165
|
+
i.putExtra("id", newId[0]);
|
166
|
+
startActivity(i);
|
167
|
+
}
|
168
|
+
});
|
169
|
+
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
170
|
+
@Override
|
171
|
+
public void onItemClick(AdapterView<?> parent, View view, int position, long l) {
|
172
|
+
ScheduleAdapter adapter = (ScheduleAdapter) list.getAdapter();
|
173
|
+
Schedule sc = adapter.getItem(position);
|
174
|
+
Intent i = new Intent(MainActivity.this, ShowActivity.class);
|
175
|
+
i.putExtra("id", sc.id);
|
176
|
+
//でかいミス発生!そしててこずった!putExtraのnameはgetExtraと揃えること。大文字小文字まできっちりと。
|
177
|
+
startActivity(i);
|
178
|
+
}
|
179
|
+
});
|
180
|
+
list.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
181
|
+
@Override
|
182
|
+
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
|
183
|
+
ScheduleAdapter adapter = (ScheduleAdapter) list.getAdapter();
|
184
|
+
final Schedule sc = adapter.getItem(position);//データベースからposition取得。select文の代わりになる
|
185
|
+
mrealm.executeTransaction(new Realm.Transaction() {
|
186
|
+
@Override
|
187
|
+
public void execute(Realm realm) {
|
188
|
+
sc.deleteFromRealm();
|
189
|
+
}
|
190
|
+
});
|
191
|
+
Snackbar.make(view,"削除しました",Snackbar.LENGTH_LONG)
|
192
|
+
.setAction("OK", new View.OnClickListener() { //スナックバーはアクションを追加できる
|
193
|
+
@Override
|
194
|
+
public void onClick(View v) {
|
195
|
+
Snackbar.make(v,"OKが押された時の処理",Snackbar.LENGTH_SHORT).show();
|
196
|
+
}})
|
197
|
+
.show();
|
198
|
+
return true;
|
199
|
+
}});}
|
200
|
+
|
201
|
+
@Override
|
202
|
+
protected void onDestroy() {
|
203
|
+
super.onDestroy();
|
204
|
+
mrealm.close();}}
|
205
|
+
|
78
206
|
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Realmを使ってデータベースから取得したのですが、表示のされ方が周りのものと違います。文字列をそのまま取り出せないでしょうか。
|
2
2
|
|
3
|
-
同じプログラムで私だけが、どうも数式みたいなのが表示されます。
|
3
|
+
同じプログラムで私だけが、どうも数式みたいなのが表示されます。何らかの設定のミスかなと疑っている次第なのですが。
|
4
4
|
|
5
5
|

|
6
6
|
|