teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

5

プログラムの追加、問題点の明記

2020/09/07 13:13

投稿

android_app_tw
android_app_tw

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- アプ内に画像を保存して、読み出しをしたい
1
+ ギャラーから読み込んだ画像を、アプリの画面に保存させたい
body CHANGED
@@ -1,8 +1,8 @@
1
1
  現在、アプリ開発の勉強中です。
2
- アプリ内に画像を保存して、読み出しをしたいと考えています。
3
- 現在、ギャラリーから画像を持ってきて表示させるところまでできましたが、その先の保存して読み出しをする方がわかりません。
2
+ ギャラリーから画像を持ってきて、アプリの画面に表示させるところまでできましたが、その先の画面内に保存し、アプリ閉じて再起動させたときに残っているようにするやり方がわかりません。
4
3
  今できているコードを以下に載せます。
5
-
4
+ MainActivity
5
+ ```
6
6
  public class MainActivity extends AppCompatActivity {
7
7
  private static final int RESULT_PICK_IMAGEFILE = 1001;
8
8
  private ImageView imageView;
@@ -54,7 +54,44 @@
54
54
  }
55
55
  }
56
56
  }
57
+ //このBitmap画像をどのように画面に保存するのかが問題//
58
+ //アプリを閉じて再起動させたときに、表示させた画像が残っているようにしたい//
57
59
  }
60
+ ```
61
+ ```ここに言語を入力
62
+ <?xml version="1.0" encoding="utf-8"?>
63
+ <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
64
+ xmlns:app="http://schemas.android.com/apk/res-auto"
65
+ xmlns:tools="http://schemas.android.com/tools"
66
+ android:layout_width="match_parent"
67
+ android:layout_height="match_parent"
68
+ tools:context=".MainActivity">
58
69
 
70
+ <ImageView
71
+ android:id="@+id/imageEdit"
72
+ android:layout_width="wrap_content"
73
+ android:layout_height="wrap_content"
74
+ app:layout_constraintBottom_toBottomOf="parent"
75
+ app:layout_constraintEnd_toEndOf="parent"
76
+ app:layout_constraintHorizontal_bias="0.498"
77
+ app:layout_constraintStart_toStartOf="parent"
78
+ app:layout_constraintTop_toTopOf="parent"
79
+ app:layout_constraintVertical_bias="0.476"
80
+ app:srcCompat="@drawable/ic_launcher_foreground" />
81
+
82
+ <Button
83
+ android:id="@+id/button"
84
+ android:layout_width="wrap_content"
85
+ android:layout_height="wrap_content"
86
+ android:text="Button"
87
+ app:layout_constraintBottom_toBottomOf="parent"
88
+ app:layout_constraintEnd_toEndOf="parent"
89
+ app:layout_constraintStart_toStartOf="parent"
90
+ app:layout_constraintTop_toBottomOf="@+id/imageEdit" />
91
+ //ここに保存ボタンを追加したい//
92
+
93
+ </androidx.constraintlayout.widget.ConstraintLayout>
94
+ ```
95
+ ここにもう一つ,保存ボタンを追加(SaveOnClickなど使って)したいと考えています。
59
96
  どのような処理を追加すればよいのかわからない状態なので、教えていただければと思います。
60
97
  また、可能であれば追加するプログラムを全文載せていただければと思います。

4

説明を追加しました。

2020/09/07 13:13

投稿

android_app_tw
android_app_tw

スコア4

title CHANGED
@@ -1,1 +1,1 @@
1
- ギャラーから画像を取得して、アプリの画面に保存させたい
1
+ アプ内に画像を保存して、読み出しをしたい
body CHANGED
@@ -1,7 +1,7 @@
1
1
  現在、アプリ開発の勉強中です。
2
- ギャラリーから得た画像をアプリの画面に表示・保存し、アプリを再び起動したときに、記憶したものを呼び出してimageviewに表示させたいと考えています。
3
- また、ここもう一つ「保存ボタン」追加したいと考えています。
2
+ アプリ内画像を保存して、読み出しをしたいと考えています。
3
+ 現在、ギャラリーから画像を持ってきて表示させるところまでできましたが、その先の保存して読み出しをする方法がわかりません。
4
- とりあえず今できていることは、ギャラリから画像表示するところでです。
4
+ 今できている以下に載せます。
5
5
 
6
6
  public class MainActivity extends AppCompatActivity {
7
7
  private static final int RESULT_PICK_IMAGEFILE = 1001;
@@ -12,7 +12,7 @@
12
12
  super.onCreate(savedInstanceState);
13
13
  setContentView(R.layout.activity_main);
14
14
 
15
- imageView = findViewById(R.id.imageEdit);
15
+ imageView = findViewById(R.id.imageView1);
16
16
  Button inputbutton = findViewById(R.id.button);
17
17
  inputbutton.setOnClickListener(new View.OnClickListener() {
18
18
  public void onClick(View v) {

3

説明を追加しました。

2020/09/04 07:26

投稿

android_app_tw
android_app_tw

スコア4

title CHANGED
File without changes
body CHANGED
@@ -2,7 +2,6 @@
2
2
  ギャラリーから得た画像をアプリの画面に表示・保存し、アプリを再び起動したときに、記憶したものを呼び出してimageviewに表示させたいと考えています。
3
3
  また、ここにもう一つ「保存ボタン」を追加したいとも考えています。
4
4
  とりあえず今できていることは、ギャラリーから画像を表示するところまでです。
5
- 今できているプログラムはこのような感じです。
6
5
 
7
6
  public class MainActivity extends AppCompatActivity {
8
7
  private static final int RESULT_PICK_IMAGEFILE = 1001;

2

説明を追加しました。

2020/08/29 08:18

投稿

android_app_tw
android_app_tw

スコア4

title CHANGED
File without changes
body CHANGED
@@ -1,5 +1,7 @@
1
1
  現在、アプリ開発の勉強中です。
2
- Sharedpreferenceを使って、ギャラリーから得た画像をアプリの画面に表示・保存し、アプリを再び起動したときに、記憶したものを呼び出してimageviewに表示させたいと考えています。
2
+ ギャラリーから得た画像をアプリの画面に表示・保存し、アプリを再び起動したときに、記憶したものを呼び出してimageviewに表示させたいと考えています。
3
+ また、ここにもう一つ「保存ボタン」を追加したいとも考えています。
4
+ とりあえず今できていることは、ギャラリーから画像を表示するところまでです。
3
5
  今できているプログラムはこのような感じです。
4
6
 
5
7
  public class MainActivity extends AppCompatActivity {
@@ -10,8 +12,6 @@
10
12
  protected void onCreate(Bundle savedInstanceState) {
11
13
  super.onCreate(savedInstanceState);
12
14
  setContentView(R.layout.activity_main);
13
-
14
- SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
15
15
 
16
16
  imageView = findViewById(R.id.imageEdit);
17
17
  Button inputbutton = findViewById(R.id.button);
@@ -23,14 +23,6 @@
23
23
  startActivityForResult(intent, RESULT_PICK_IMAGEFILE);
24
24
  }
25
25
  });
26
-
27
- Button saveButton = (Button)findViewById(R.id.SaveButton);
28
- saveButton.setOnClickListener(new View.OnClickListener() {
29
- @Override
30
- public void onClick(View arg0) {
31
- saveButtonClick();
32
- }
33
- });
34
26
  }
35
27
 
36
28
  @Override

1

修正しました

2020/08/28 06:00

投稿

android_app_tw
android_app_tw

スコア4

title CHANGED
File without changes
body CHANGED
@@ -12,8 +12,7 @@
12
12
  setContentView(R.layout.activity_main);
13
13
 
14
14
  SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
15
- String saveString = sp.getString("SaveString", "");
15
+
16
-
17
16
  imageView = findViewById(R.id.imageEdit);
18
17
  Button inputbutton = findViewById(R.id.button);
19
18
  inputbutton.setOnClickListener(new View.OnClickListener() {