2017-05-01 17 views
0

私はカスタムグリッドビューを作成しようとしています。そのため、1つのグリッドの外観を操作できますが、成功しませんでした。カスタムGridViewの作成方法

私はボレーを使用してイメージとテキストを取得するだけのグリッドビューを作成できました。そして 私はアダプタクラスを操作してチュートリアルを検索しようとしていますが、残念なことに運はありません。

あなたは私がそれをどうやってやることができて、何が間違っているのか私に助けてくれますか?前もって感謝します!

これは私のアダプタクラスGridViewAdaperです:

public class GridViewAdapter extends BaseAdapter { 

    private ImageLoader imageLoader; 


    private Context context; 

    private ArrayList<String> images; 
    private ArrayList<String> names; 

    public GridViewAdapter (Context context, ArrayList<String> images, ArrayList<String> names){ 
     this.context = context; 
     this.images = images; 
     this.names = names; 
    } 

    @Override 
    public int getCount() { 
     return images.size(); 
    } 

    @Override 
    public Object getItem(int position) { 
     return images.get(position); 
    } 

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

    @Override 
    public View getView(int position, View convertView, ViewGroup parent) { 

     LayoutInflater inflater= (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
     convertView=inflater.inflate(R.layout.list_item, null); 

     TextView name=(TextView)convertView.findViewById(R.id.textViewName); 
     ImageView icon=(NetworkImageView)convertView.findViewById(R.id.imageViewHero); 

     imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader(); 
     imageLoader.get(images.get(position), ImageLoader.getImageListener(icon, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert)); 

     icon.setImageResource(images.get(position),imageLoader); 

     name.setText(names.get(position)); 

     icon.setScaleType(ImageView.ScaleType.CENTER_CROP); 
     icon.setLayoutParams(new GridView.LayoutParams(200,200)); 

     return convertView; 
    } 
} 

答えて

0

まあ、私はすでにこの問題を解決:D

アダプタクラス:

public class GridViewAdapter extends BaseAdapter { 

private ImageLoader imageLoader; 

private Context context; 

private ArrayList<String> images; 
private ArrayList<String> names; 

public GridViewAdapter (Context context,ArrayList<String> images, 
ArrayList<String> names){ 
    this.context = context; 
    this.images = images; 
    this.names = names; 
} 

@Override 
public int getCount() { 
    return images.size(); 
} 

@Override 
public Object getItem(int position) { 
    return images.get(position); 
} 

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

@Override 
public View getView(int position, View convertView, ViewGroup parent) { 

    View grid; 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 
    grid = inflater.inflate(R.layout.list_item, null); 

    TextView title = (TextView) grid.findViewById(R.id.textViewName); 
    NetworkImageView thumbNail = (NetworkImageView) grid.findViewById(R.id.imageViewHero); 

    imageLoader = CustomVolleyRequest.getInstance(context).getImageLoader(); 
    imageLoader.get(images.get(position), ImageLoader.getImageListener(thumbNail, R.mipmap.ic_launcher, android.R.drawable.ic_dialog_alert)); 

    title.setText(names.get(position)); 
    thumbNail.setImageUrl(images.get(position), imageLoader); 


    return grid; 
} 
} 
関連する問題