2012-02-02 23 views
0

すべて私はRSSフィードからいくつかの画像データを表示したいと思います。私のRSSフィードコードはうまくいきました。フィードから正しく読み込まれましたが、イメージを水平に表示できませんでしたか?私はギャラリーを使ってみましたが、イメージを入れることができませんでしたか?同じことを達成する方法はありますか?水平に表示する?

また、http://www.dev-smart.com/archives/34のリンクを参照してHorizo​​ntal ListViewを実装していますが、リストにonClickListenerを実装できません。助けてください。ありがとうございました。

私はギャラリーのためにしようとしたコード..

パブリッククラスImageAdapterはBaseAdapter あなたがgalleryholder.xmlを使用することができます{

int imageBackground; 
private List<RSSIteam> objects = null; 
private Context context; 

public ImageAdapter(Context c) 
{ 
    context = c; 
    TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1); 
    imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1); 
    ta.recycle(); 
} 

public ImageAdapter(Context context, int textViewResourceId, List<RSSIteam> objects) 
{ 
    super(); 
    this.context = context; 
    this.objects = objects; 
} 

    @Override 
    public int getCount() 
    { 
     return this.objects.size(); 
     //return pics.length; 

    } 

    @Override 
    public Object getItem(int position) 
    { 
     return this.objects.get(position); 
     //return position; 
    } 

    @Override 
    public long getItemId(int position) 
    { 
     return position; 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) 
    { 
     RSSIteam data = (RSSIteam) getItem(position); 
     String imageUrl = data.imageurl; 
     try 
    { 
      URL feedImage = new URL(imageUrl); 
      HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection(); 
      InputStream is = conn.getInputStream(); 
      Bitmap img = BitmapFactory.decodeStream(is); 



     } 
    catch (MalformedURLException e) 
    { 
      e.printStackTrace(); 
     } 
    catch (IOException e) 
    { 
      e.printStackTrace(); 
     } 



     ImageView iv = new ImageView(context); 
     iv.setImageResource(img[position]); //here i am unable to set the image in particular position because it require int type array 
     iv.setScaleType(ImageView.ScaleType.FIT_XY); 
     iv.setLayoutParams(new Gallery.LayoutParams(90,70)); 
    iv.setBackgroundResource(imageBackground); 
    return iv; 

    } 

}

+0

を操作するための完全な助けされるコードの下に、これを見て - あなたの試したコードを投稿してください。 – user370305

答えて

0

を拡張します。このxmlにはimageviewが含まれており、アダプタで膨張させてビューを返し、アダプタがこのビューをギャラリーに埋め込んでいます。

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="100dp" 
    android:layout_height="fill_parent" 
    android:background="@drawable/my_border" 
    android:orientation="vertical" 
    android:padding="5dp" > 


      <ImageView 
       android:id="@+id/storyImage" 
       android:layout_width="fill_parent" 
       android:layout_height="70dp" 
       android:scaleType="fitXY" /> 

</LinearLayout> 

and use Image adapter to fill the gallery 

galleryID.setAdapter(new ImageAdapter()); 

Image Adapter code 


    @Override 
     public View getView(int position, View convertView, ViewGroup parent) 
     { 
    LayoutInflater layoutInflater=(LayoutInflater) 
        context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
      View view=(View)layoutInflater.inflate(R.layout.galleryholder,parent,false); 
     ImageView iv; 
      if(convertView==null){ 

       convertView=view; 
       iv=(ImageView)view.findViewById(R.id.storyImage); 

      } 
      RSSIteam data = (RSSIteam) getItem(position); 
      String imageUrl = data.imageurl; 
      try 
     { 
       URL feedImage = new URL(imageUrl); 
       HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection(); 
       InputStream is = conn.getInputStream(); 
       Bitmap img = BitmapFactory.decodeStream(is); 



      } 
     catch (MalformedURLException e) 
     { 
       e.printStackTrace(); 
      } 
     catch (IOException e) 
     { 
       e.printStackTrace(); 
      } 



      iv.setImageResource(img[position]); //here i am unable to set the image in particular position because it require int type array 
      iv.setScaleType(ImageView.ScaleType.FIT_XY); 
      iv.setLayoutParams(new Gallery.LayoutParams(90,70)); 
     iv.setBackgroundResource(imageBackground); 
     return convertView; 

     } 
0

「私はギャラリーと試みたが、それに画像を置くことができない... ???」you.itは細かい

@Override 
    public View getView(int position, View convertView, ViewGroup parent) { 
     /* 
     * // here i am setting the text color and bckgroung of layout // 
     * According to time if (6 <= (new Date()).getHours() && (new 
     * Date()).getHours() <= 17) { ll.setBackgroundColor(Color.BLACK); 
     * label.setTextColor(Color.WHITE); } else { 
     * ll.setBackgroundColor(Color.WHITE); 
     * label.setTextColor(Color.BLACK); } 
     */ 
     // return (row); 

     View v = convertView; 
     if (v == null) { 

      LayoutInflater inflater = context.getLayoutInflater(); 
      v = inflater.inflate(R.layout.myrow, null); 
     } 
     Item o = itemsCmn.get(position); 
     if (o != null) { 
      TextView tt = (TextView) v.findViewById(R.id.label); 
      ImageView icon = (ImageView) v.findViewById(R.id.icon); 
      if (tt != null) { 
       tt.setText(o.getTitle()); 
      } 
      else{ 

      } 
      if (icon != null) { 
       if (o.getImg() != null) { 
        icon.setImageBitmap(BitmapFactory.decodeByteArray(
          o.getImg(), 0, o.getImg().length)); 
       }else{ 
        icon.setImageResource(R.drawable.images); 
       } 
      } 
     } 
     return v; 
    }// getView 
関連する問題