質問編集履歴
4
フラグメントのjavaコードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -106,11 +106,9 @@
|
|
106
106
|
|
107
107
|
```
|
108
108
|
|
109
|
+
```java
|
110
|
+
Main.Activity.java
|
109
111
|
|
110
|
-
|
111
|
-
|
112
|
-
```MainActivity.java
|
113
|
-
|
114
112
|
package com.example.taiki.grasphand;
|
115
113
|
|
116
114
|
import android.os.Bundle;
|
@@ -157,4 +155,120 @@
|
|
157
155
|
|
158
156
|
}
|
159
157
|
|
158
|
+
```
|
159
|
+
|
160
|
+
```java
|
161
|
+
page1.java
|
162
|
+
|
163
|
+
package com.example.taiki.grasphand;
|
164
|
+
|
165
|
+
import android.content.Context;
|
166
|
+
import android.net.Uri;
|
167
|
+
import android.os.Bundle;
|
168
|
+
import android.support.v4.app.Fragment;
|
169
|
+
import android.view.LayoutInflater;
|
170
|
+
import android.view.View;
|
171
|
+
import android.view.ViewGroup;
|
172
|
+
|
173
|
+
|
174
|
+
/**
|
175
|
+
* A simple {@link Fragment} subclass.
|
176
|
+
* Activities that contain this fragment must implement the
|
177
|
+
* {@link page1.OnFragmentInteractionListener} interface
|
178
|
+
* to handle interaction events.
|
179
|
+
* Use the {@link page1#newInstance} factory method to
|
180
|
+
* create an instance of this fragment.
|
181
|
+
*/
|
182
|
+
public class page1 extends Fragment {
|
183
|
+
// TODO: Rename parameter arguments, choose names that match
|
184
|
+
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
185
|
+
private static final String ARG_PARAM1 = "param1";
|
186
|
+
private static final String ARG_PARAM2 = "param2";
|
187
|
+
|
188
|
+
// TODO: Rename and change types of parameters
|
189
|
+
private String mParam1;
|
190
|
+
private String mParam2;
|
191
|
+
|
192
|
+
private OnFragmentInteractionListener mListener;
|
193
|
+
|
194
|
+
public page1() {
|
195
|
+
// Required empty public constructor
|
196
|
+
}
|
197
|
+
|
198
|
+
/**
|
199
|
+
* Use this factory method to create a new instance of
|
200
|
+
* this fragment using the provided parameters.
|
201
|
+
*
|
202
|
+
* @param param1 Parameter 1.
|
203
|
+
* @param param2 Parameter 2.
|
204
|
+
* @return A new instance of fragment page1.
|
205
|
+
*/
|
206
|
+
// TODO: Rename and change types and number of parameters
|
207
|
+
public static page1 newInstance(String param1, String param2) {
|
208
|
+
page1 fragment = new page1();
|
209
|
+
Bundle args = new Bundle();
|
210
|
+
args.putString(ARG_PARAM1, param1);
|
211
|
+
args.putString(ARG_PARAM2, param2);
|
212
|
+
fragment.setArguments(args);
|
213
|
+
return fragment;
|
214
|
+
}
|
215
|
+
|
216
|
+
|
217
|
+
|
218
|
+
@Override
|
219
|
+
public void onCreate(Bundle savedInstanceState) {
|
220
|
+
super.onCreate(savedInstanceState);
|
221
|
+
if (getArguments() != null) {
|
222
|
+
mParam1 = getArguments().getString(ARG_PARAM1);
|
223
|
+
mParam2 = getArguments().getString(ARG_PARAM2);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
@Override
|
228
|
+
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
229
|
+
Bundle savedInstanceState) {
|
230
|
+
// Inflate the layout for this fragment
|
231
|
+
return inflater.inflate(R.layout.fragment_page1, container, false);
|
232
|
+
}
|
233
|
+
|
234
|
+
// TODO: Rename method, update argument and hook method into UI event
|
235
|
+
public void onButtonPressed(Uri uri) {
|
236
|
+
if (mListener != null) {
|
237
|
+
mListener.onFragmentInteraction(uri);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
|
241
|
+
@Override
|
242
|
+
public void onAttach(Context context) {
|
243
|
+
super.onAttach(context);
|
244
|
+
if (context instanceof OnFragmentInteractionListener) {
|
245
|
+
mListener = (OnFragmentInteractionListener) context;
|
246
|
+
} else {
|
247
|
+
throw new RuntimeException(context.toString()
|
248
|
+
+ " must implement OnFragmentInteractionListener");
|
249
|
+
}
|
250
|
+
}
|
251
|
+
|
252
|
+
@Override
|
253
|
+
public void onDetach() {
|
254
|
+
super.onDetach();
|
255
|
+
mListener = null;
|
256
|
+
}
|
257
|
+
|
258
|
+
/**
|
259
|
+
* This interface must be implemented by activities that contain this
|
260
|
+
* fragment to allow an interaction in this fragment to be communicated
|
261
|
+
* to the activity and potentially other fragments contained in that
|
262
|
+
* activity.
|
263
|
+
* <p>
|
264
|
+
* See the Android Training lesson <a href=
|
265
|
+
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
266
|
+
* >Communicating with Other Fragments</a> for more information.
|
267
|
+
*/
|
268
|
+
public interface OnFragmentInteractionListener {
|
269
|
+
// TODO: Update argument type and name
|
270
|
+
void onFragmentInteraction(Uri uri);
|
271
|
+
}
|
272
|
+
}
|
273
|
+
|
160
274
|
```
|
3
コードの一部を更新
title
CHANGED
File without changes
|
body
CHANGED
@@ -129,15 +129,16 @@
|
|
129
129
|
|
130
130
|
@Override
|
131
131
|
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
132
|
+
//Fragment selectedFragment = null;
|
132
133
|
switch (item.getItemId()) {
|
133
134
|
case R.id.navigation_home:
|
135
|
+
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
134
|
-
|
136
|
+
transaction.replace(R.id.container, page1.newInstance());
|
137
|
+
transaction.commit();
|
135
138
|
return true;
|
136
139
|
case R.id.navigation_dashboard:
|
137
|
-
mTextMessage.setText(R.string.title_dashboard);
|
138
140
|
return true;
|
139
141
|
case R.id.navigation_notifications:
|
140
|
-
mTextMessage.setText(R.string.title_notifications);
|
141
142
|
return true;
|
142
143
|
}
|
143
144
|
return false;
|
2
javaファイル追記しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -104,4 +104,56 @@
|
|
104
104
|
|
105
105
|
</android.support.constraint.ConstraintLayout>
|
106
106
|
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
```MainActivity.java
|
113
|
+
|
114
|
+
package com.example.taiki.grasphand;
|
115
|
+
|
116
|
+
import android.os.Bundle;
|
117
|
+
import android.support.annotation.NonNull;
|
118
|
+
import android.support.design.widget.BottomNavigationView;
|
119
|
+
import android.support.v7.app.AppCompatActivity;
|
120
|
+
import android.view.MenuItem;
|
121
|
+
import android.widget.TextView;
|
122
|
+
|
123
|
+
public class MainActivity extends AppCompatActivity {
|
124
|
+
|
125
|
+
private TextView mTextMessage;
|
126
|
+
|
127
|
+
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
128
|
+
= new BottomNavigationView.OnNavigationItemSelectedListener() {
|
129
|
+
|
130
|
+
@Override
|
131
|
+
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
132
|
+
switch (item.getItemId()) {
|
133
|
+
case R.id.navigation_home:
|
134
|
+
mTextMessage.setText(R.string.title_home);
|
135
|
+
return true;
|
136
|
+
case R.id.navigation_dashboard:
|
137
|
+
mTextMessage.setText(R.string.title_dashboard);
|
138
|
+
return true;
|
139
|
+
case R.id.navigation_notifications:
|
140
|
+
mTextMessage.setText(R.string.title_notifications);
|
141
|
+
return true;
|
142
|
+
}
|
143
|
+
return false;
|
144
|
+
}
|
145
|
+
};
|
146
|
+
|
147
|
+
@Override
|
148
|
+
protected void onCreate(Bundle savedInstanceState) {
|
149
|
+
super.onCreate(savedInstanceState);
|
150
|
+
setContentView(R.layout.activity_main);
|
151
|
+
|
152
|
+
mTextMessage = (TextView) findViewById(R.id.message);
|
153
|
+
BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
|
154
|
+
navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);
|
155
|
+
}
|
156
|
+
|
157
|
+
}
|
158
|
+
|
107
159
|
```
|
1
xmlファイルのコードを追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -9,4 +9,99 @@
|
|
9
9
|
|
10
10
|
全く違う画面に切り替える予定です。
|
11
11
|
|
12
|
-

|
12
|
+

|
13
|
+
|
14
|
+
|
15
|
+
```xml
|
16
|
+
|
17
|
+
<?xml version="1.0" encoding="utf-8"?>
|
18
|
+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
19
|
+
xmlns:app="http://schemas.android.com/apk/res-auto"
|
20
|
+
xmlns:tools="http://schemas.android.com/tools"
|
21
|
+
android:id="@+id/container"
|
22
|
+
android:layout_width="match_parent"
|
23
|
+
android:layout_height="match_parent"
|
24
|
+
tools:context="@android:string/VideoView_error_button">
|
25
|
+
|
26
|
+
<TextView
|
27
|
+
android:id="@+id/message"
|
28
|
+
android:layout_width="wrap_content"
|
29
|
+
android:layout_height="21dp"
|
30
|
+
android:layout_marginTop="12dp"
|
31
|
+
android:autoText="false"
|
32
|
+
android:text="@string/game_title"
|
33
|
+
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
|
34
|
+
android:textSize="12sp"
|
35
|
+
app:fontFamily="serif"
|
36
|
+
app:layout_constraintTop_toTopOf="parent"
|
37
|
+
tools:layout_editor_absoluteX="16dp" />
|
38
|
+
|
39
|
+
<android.support.design.widget.BottomNavigationView
|
40
|
+
android:id="@+id/navigation"
|
41
|
+
android:layout_width="0dp"
|
42
|
+
android:layout_height="56dp"
|
43
|
+
android:layout_marginBottom="8dp"
|
44
|
+
android:addStatesFromChildren="true"
|
45
|
+
android:background="#733c5b81"
|
46
|
+
app:layout_constraintBottom_toBottomOf="parent"
|
47
|
+
app:layout_constraintEnd_toEndOf="parent"
|
48
|
+
app:layout_constraintLeft_toLeftOf="parent"
|
49
|
+
app:layout_constraintRight_toRightOf="parent"
|
50
|
+
app:menu="@menu/navigation">
|
51
|
+
|
52
|
+
</android.support.design.widget.BottomNavigationView>
|
53
|
+
|
54
|
+
<LinearLayout
|
55
|
+
android:layout_width="288dp"
|
56
|
+
android:layout_height="37dp"
|
57
|
+
android:orientation="horizontal"
|
58
|
+
tools:layout_editor_absoluteX="48dp"
|
59
|
+
tools:layout_editor_absoluteY="33dp">
|
60
|
+
|
61
|
+
<ImageView
|
62
|
+
android:id="@+id/imageView8"
|
63
|
+
android:layout_width="match_parent"
|
64
|
+
android:layout_height="match_parent"
|
65
|
+
android:layout_weight="1"
|
66
|
+
app:srcCompat="@drawable/hatena" />
|
67
|
+
|
68
|
+
<ImageView
|
69
|
+
android:id="@+id/imageView7"
|
70
|
+
android:layout_width="wrap_content"
|
71
|
+
android:layout_height="match_parent"
|
72
|
+
android:layout_weight="1"
|
73
|
+
app:srcCompat="@drawable/hatena" />
|
74
|
+
|
75
|
+
<ImageView
|
76
|
+
android:id="@+id/imageView6"
|
77
|
+
android:layout_width="match_parent"
|
78
|
+
android:layout_height="match_parent"
|
79
|
+
android:layout_weight="1"
|
80
|
+
app:srcCompat="@drawable/hatena" />
|
81
|
+
|
82
|
+
<ImageView
|
83
|
+
android:id="@+id/imageView5"
|
84
|
+
android:layout_width="match_parent"
|
85
|
+
android:layout_height="match_parent"
|
86
|
+
android:layout_weight="1"
|
87
|
+
app:srcCompat="@drawable/hatena"
|
88
|
+
tools:layout_editor_absoluteX="117dp"
|
89
|
+
tools:layout_editor_absoluteY="91dp" />
|
90
|
+
|
91
|
+
<Button
|
92
|
+
android:id="@+id/button"
|
93
|
+
android:layout_width="62dp"
|
94
|
+
android:layout_height="33dp"
|
95
|
+
android:text="On/Off"
|
96
|
+
android:textSize="10sp"
|
97
|
+
tools:layout_editor_absoluteX="306dp"
|
98
|
+
tools:layout_editor_absoluteY="37dp" />
|
99
|
+
|
100
|
+
</LinearLayout>
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
</android.support.constraint.ConstraintLayout>
|
106
|
+
|
107
|
+
```
|