遷移をコードを作成したのですが
遷移先のViewが白紙になってしまいます。
原因がわかりませんので
コードを解読しわかる方お願い致します。
java
1 2Product.java 3import android.content.Intent; 4import android.os.Bundle; 5import android.support.annotation.NonNull; 6import android.support.annotation.Nullable; 7import android.support.v4.app.Fragment; 8import android.view.LayoutInflater; 9import android.view.View; 10import android.view.ViewGroup; 11import android.widget.Button; 12import android.widget.ImageButton; 13import android.widget.TextView; 14 15public class Product extends Fragment { 16 17 @Nullable 18 @Override 19 public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { 20 View view = inflater.inflate(R.layout.product, container, false); 21 ImageButton imageButton = (ImageButton) view.findViewById(R.id.imageButton); // view経由でimageButtonを探す 22 imageButton.setOnClickListener(new View.OnClickListener() { 23 24 25 public void onClick(View v) { 26 Intent i = new Intent(v.getContext(), Product_box.class); 27 startActivity(i); 28 } 29 }); 30 return view; 31 } 32}
java
1 2Product_box.java 3 4import android.content.Intent; 5import android.support.v7.app.AppCompatActivity; 6import android.os.Bundle; 7import android.widget.TextView; 8 9public class Product_box extends AppCompatActivity { 10 11 @Override 12 protected void onCreate(Bundle savedInstanceState) { 13 super.onCreate(savedInstanceState); 14 15 setContentView(R.layout.activity_product_box); 16 17 Intent intent = getIntent(); 18 TextView textView = (TextView)this.findViewById(R.id.imageButton); 19 20 } 21} 22 23
java
1 2activity_product_box.xml 3 4<?xml version="1.0" encoding="utf-8"?> 5<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 6 xmlns:app="http://schemas.android.com/apk/res-auto" 7 android:layout_width="match_parent" 8 android:layout_height="match_parent" 9 android:orientation="vertical"> 10 11 <ScrollView 12 android:layout_width="match_parent" 13 android:layout_weight="1"> 14 15 <LinearLayout 16 android:layout_width="match_parent" 17 android:layout_height="wrap_content" 18 android:orientation="vertical"> 19 20 <FrameLayout 21 android:layout_width="match_parent" 22 android:layout_height="wrap_content" 23 android:layout_weight="1"> 24 25 <ImageView 26 android:id="@+id/imageView" 27 android:layout_width="match_parent" 28 android:layout_height="260dp" 29 android:layout_weight="1" 30 app:srcCompat="@drawable/box" /> 31 32 </FrameLayout> 33 34 35 <FrameLayout 36 android:layout_width="match_parent" 37 android:layout_height="match_parent" 38 android:layout_weight="1"> 39 40 <TextView 41 android:id="@+id/textView1" 42 android:layout_width="match_parent" 43 android:layout_height="34dp" 44 android:layout_weight="1" 45 android:text="タイトル" 46 android:textSize="24sp" /> 47 48 <android.support.design.widget.FloatingActionButton 49 android:id="@+id/floatingActionButton2" 50 android:layout_width="wrap_content" 51 android:layout_height="wrap_content" 52 android:layout_gravity="right" 53 android:clickable="true" 54 app:srcCompat="@android:drawable/btn_star_big_on" /> 55 56 </FrameLayout> 57 58 59 <FrameLayout 60 android:layout_width="match_parent" 61 android:layout_height="match_parent" 62 android:layout_weight="1"> 63 64 <TextView 65 android:id="@+id/textView6" 66 android:layout_width="wrap_content" 67 android:layout_height="wrap_content" 68 android:text="〜〜〜 69〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜〜" /> 70 71 </FrameLayout> 72 73 74 <FrameLayout 75 android:layout_width="match_parent" 76 android:layout_height="match_parent" 77 android:layout_weight="1"> 78 79 <android.support.design.widget.FloatingActionButton 80 android:id="@+id/floatingActionButton" 81 android:layout_width="wrap_content" 82 android:layout_height="wrap_content" 83 android:clickable="true" 84 app:srcCompat="@drawable/ic_cart_black_24dp" /> 85 86 <Button 87 android:id="@+id/button2" 88 android:layout_width="wrap_content" 89 android:layout_height="match_parent" 90 android:layout_gravity="right" 91 android:text="購入画面" 92 android:textStyle="bold" /> 93 </FrameLayout> 94 95 96 <FrameLayout 97 android:layout_width="match_parent" 98 android:layout_height="match_parent" 99 android:layout_weight="1"> 100 101 </FrameLayout> 102 </LinearLayout> 103 </ScrollView> 104 105</LinearLayout> 106
回答1件
あなたの回答
tips
プレビュー