2017-09-24 7 views
0

私は8種類の異なるイメージ(レイヤーベース)でロードされた8種類の異なるレイアウトを持っています。レイアウトの一番下には、gridviewを使用しています。アダプタを使用して別の5つの画像を読み込みます。スクリーンショットはこちらapplication layout。ユーザーがgridviewイメージをクリックすると、対応するイメージがimageviewに読み込まれます。しかし今、ユーザーが各gridview画像をクリックしたときに何も起こっていません。私がどこに間違って行ったのか分からない。ここでイメージビューが新しいイメージで更新されない

は私のXMLである:ここでは

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="com.keikomat.austurn.keikomaterialdesign.TwoFragment"> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="71dp" 
     app:srcCompat="@drawable/face1" /> 

    <ImageView 
     android:id="@+id/imageView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" 
     android:layout_alignTop="@+id/imageView1" 
     app:srcCompat="@drawable/eyes1" /> 

    <ImageView 
     android:id="@+id/imageView4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/eb1" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" /> 

    <ImageView 
     android:id="@+id/imageView5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     app:srcCompat="@drawable/ns1" 
     android:layout_alignTop="@+id/imageView1" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" /> 

    <ImageView 
     android:id="@+id/imageView6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" 
     android:layout_alignTop="@+id/imageView1" 
     app:srcCompat="@drawable/ear1" /> 

    <ImageView 
     android:id="@+id/imageView7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" 
     android:layout_alignTop="@+id/imageView1" 
     app:srcCompat="@drawable/lips1" /> 

    <ImageView 
     android:id="@+id/imageView8" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" 
     android:layout_alignTop="@+id/imageView1" 
     app:srcCompat="@drawable/mst1" /> 

    <ImageView 
     android:id="@+id/imageView9" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/imageView1" 
     android:layout_alignStart="@+id/imageView1" 
     android:layout_alignTop="@+id/imageView1" 
     app:srcCompat="@drawable/hair1" /> 

    <Spinner 
     android:id="@+id/spinner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" 
     android:layout_below="@+id/imageView1" /> 

    <GridView 
     android:id="@+id/gridviewShapes" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/spinner" 
     android:columnWidth="90dp" 
     android:numColumns="5" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 
</RelativeLayout> 

は私のJavaです:

public class TwoFragment extends Fragment { 
    private ImageView head; 

    ArrayList<Integer> item_ids = new ArrayList<Integer>(); 

    public TwoFragment() { 
     // Required empty public constructor 
    } 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
    } 

    @Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { 
     final View view1 = inflater.inflate(R.layout.fragment_two,container,true); 
     View view = inflater.inflate(R.layout.fragment_two,container,false); 
     GridView gridView = (GridView) view.findViewById(R.id.gridviewShapes); 
     gridView.setAdapter(new GridViewAdapterFace(view.getContext())); // uses the view to get the context instead of getActivity(). 
     gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
      @Override 
      public void onItemClick(AdapterView<?> a, View v,int position, long id) { 
       if (position == 0) { 
        // RelativeLayout im =(RelativeLayout)view1; 
        ImageView i=(ImageView)view1.findViewById(R.id.imageView1); 
        i.setImageResource(R.drawable.face5); 
       } else if (position == 1) { 

       } else if (position == 2) { 

       } else if (position == 3) { 

       } else if (position == 4) { 

       } else if (position == 5) { 

       } 
      } 
     }); 

     return view; 
    } 
} 

答えて

0

はすべてimageviews

android:focusable="false" 
android:focusableInTouchMode="false" 

にこれを追加し、この

i.setImageDrawable(getResources().getDrawable(R.drawable.star_off)); 
のように画像を設定してみてください
+0

ありがとう、それらを追加しましたが、変更はごめんなさい。 – AjKu

+0

i.setImageResource(R.drawable.face5);これはどこにロードされていないのですか – AjKu

+0

一度私の編集を確認してください –