2012-03-05 10 views
2

どのようにして写真をいくつかの情報で切り替えることができますか?私たちは画像を切り替えると、情報はまた、アンドロイドのギャラリービューで切り替える必要があります。画像設定アンドロイドのギャラリービュー

public class ImageAdapter extends BaseAdapter { 
     String[] Merchantname=null,Cardname=null,Points=null,Expirydate=null,status=null; 
     private Context ctx; 
     int imageBackground; 
     Bitmap[] image_data; 

     public ImageAdapter(Context c, Bitmap []card_image,String [] Merchantname,String [] Cardname,String []points,String[] Expirydate, String []status) { 
      ctx = c; 
      image_data = card_image; 
      TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1); 
      imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1); 
      ta.recycle(); 
      this.Merchantname=Merchantname; 
      this.Cardname=Cardname; 
      this.Points=points; 
      this.Expirydate=Expirydate; 
      this.status=status; 
     } 

     public int getCount() { 

      return image_data.length; 
     } 

     public Object getItem(int arg0) { 

      return arg0; 
     } 

     public long getItemId(int arg0) { 

      return arg0; 
     } 

     public View getView(int position, View arg1, ViewGroup arg2) { 
      TextView tv1,tv2,tv3,tv4,tv5; 
      ImageView i ;//= new ImageView(this.ctx); 
      if (arg1 == null) { 
       i = new ImageView(this.ctx); 
      } else { 
       i = (ImageView) arg1; 
      } 

      tv1=(TextView)findViewById(R.id.Merchantname); 
      tv2=(TextView)findViewById(R.id.Cardname); 
      tv3=(TextView)findViewById(R.id.Expirydate); 
      tv4=(TextView)findViewById(R.id.status); 

      tv1.setText(Merchantname[position]); 
      tv2.setText(Cardname[position]); 
      tv3.setText(Expirydate[position]); 
      tv4.setText(status[position]); 

//   ImageView iv = new ImageView(ctx); 
//   Drawable drawable = new BitmapDrawable(getResources(), image_data[position]); 
      i.setImageBitmap(image_data[position]); 
      i.setImageDrawable(new BitmapDrawable(getResources(), image_data[position])); 
      i.setScaleType(ImageView.ScaleType.FIT_XY); 
      i.setLayoutParams(new Gallery.LayoutParams(300,200)); 
      i.setBackgroundResource(imageBackground); 
      return i; 
     } 

    } 
+0

getViewメソッド layout =()c.getLayoutInflater()。inflate(レイアウトレイアウトのXML名、null); change tv1 =(TextView)layout.findViewById(R.id.Merchantname); ...また、ImageViewをこのレイアウトに追加し、このレイアウトオブジェクトを返します。 – Natali

答えて

0

あなたsetOnItemClickListenerコンテンツを変更するために位置変数を使用するには、ギャラリーを見るの長さにマッチするインデックスGallery views個々のビューとリンクされるだろうArrayList、とのArrayListのレンスを使用する単純な必要性同じインデックスに一致する配列の一覧から

// Reference the Gallery view 
    Gallery g = (Gallery) findViewById(R.id.gallery); 
    // Set the adapter to our custom adapter (below) 
    g.setAdapter(new ImageAdapter(this)); 

    // Set a item click listener, and just Toast the clicked position 
    g.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView parent, View v, int position, long id) { 
      Toast.makeText(Gallery1.this, "" + position, Toast.LENGTH_SHORT).show(); 
     } 
    }); 
+0

私は私QUEを更新しているしてください – user1196969

0

ImageViewTextViewでレイアウトを作成します。 Galleryのカスタムアダプタを書き、とTextViewの値をgetViewに設定してください。彼らはあなたのGalleryにこのアダプタを設定します。

+0

が同じことをやって表示されるはずですが、NullPointerExceptionが – user1196969

+0

はあなたのコードを投稿します、ClickListenerを設定したくありません – Natali

+0

plzのチェックアウトは、コードを追加して、我々はスクロールするとその画像に関連する情報を動的に – user1196969

0

問題は、LayoutFileを求める前に、親ビューに言及すべてTextViewsため(TextView)arg1.findViewById()を追加し、私たちが知っているのを忘れて

tv1=(TextView)findViewById(R.id.Merchantname); 
    tv2=(TextView)findViewById(R.id.Cardname); 
    tv3=(TextView)findViewById(R.id.Expirydate); 
    tv4=(TextView)findViewById(R.id.status); 

、ここに位置しています。 希望します。

関連する問題