0

我是 android 的初学者程序员,我需要更改我的画廊控件,并阅读有关 Devsmart 水平列表视图控件的信息,但我无法运行它。

我使用来自 Web 服务的整数数组来动态填充我的旧画廊控件。我怎样才能填充horizo​​ntalllistview?

...在此刻:

private void llenagallery() {

        int i,Id;
        for ( i = 0; i<(Servicios.length()); i++) {

            String valor = Character.toString(Servicios.charAt(i));

            if (valor.equals("a")) {
                Id = this.getResources().getIdentifier("a", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("b")) {
                Id = this.getResources().getIdentifier("b", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("c")) {
                Id = this.getResources().getIdentifier("c", "drawable", this.getPackageName());
                imagenes.add(Id);   
            }else if (valor.equals("d")) {
                Id = this.getResources().getIdentifier("d", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("e")) {
                Id = this.getResources().getIdentifier("e", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("f")) {
                Id = this.getResources().getIdentifier("f", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("g")) {
                Id = this.getResources().getIdentifier("g", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("i")) {
                Id = this.getResources().getIdentifier("i", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("j")) {
                Id = this.getResources().getIdentifier("j", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("l")) {
                Id = this.getResources().getIdentifier("l", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("m")) {
                Id = this.getResources().getIdentifier("m", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("n")) {
                Id = this.getResources().getIdentifier("n", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("o")) {
                Id = this.getResources().getIdentifier("o", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("p")) {
                Id = this.getResources().getIdentifier("p", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("r")) {
                Id = this.getResources().getIdentifier("r", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("s")) {
                Id = this.getResources().getIdentifier("s", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("t")) {
                Id = this.getResources().getIdentifier("t", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("u")) {
                Id = this.getResources().getIdentifier("u", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("v")) {
                Id = this.getResources().getIdentifier("v", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("w")) {
                Id = this.getResources().getIdentifier("w", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("y")) {
                Id = this.getResources().getIdentifier("y", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("z")) {
                Id = this.getResources().getIdentifier("z", "drawable", this.getPackageName());
                imagenes.add(Id);   
            }else if (valor.equals("P")) {
                Id = this.getResources().getIdentifier("euro1", "drawable", this.getPackageName());
                imagenes.add(Id);
            }else if (valor.equals("h")) {
                Id = this.getResources().getIdentifier("euro2", "drawable", this.getPackageName());
                imagenes.add(Id);   
            }
        }                                 

        HorizontalListView hscroll = (HorizontalListView)findViewById(R.id.iconos);
    hscroll.setAdapter(new ImageAdapter(this,imagenes));

但是当调试程序时,什么都没有显示(动态图标)谢谢,对不起我的英语。

编辑:这是我的 ImageAdapter:

public class ImageAdapter extends BaseAdapter {

List<Integer> imageIDs;
private Context context;

public ImageAdapter(Context c, List<Integer> imagenes) 
{
    context = c;
    imageIDs = imagenes;
}

//---returns the number of images---
public int getCount() {
    return imageIDs.size();
}

//---returns the ID of an item--- 
public Object getItem(int position) {
    return position;
}

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

//---returns an ImageView view---
public View getView(int position, View convertView, ViewGroup parent) 
{
        ImageView imageView = new ImageView(this.context);
        imageView.setImageResource(imageIDs.get(position));
        imageView.setLayoutParams(new HorizontalListView.LayoutParams(120,120));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        //imageView.setBackgroundResource(mItemBackground);
        return imageView;
}    

}

感谢帮助。

4

1 回答 1

0

很难知道为什么没有显示任何内容,因为此代码仅显示填充列表。

如果换了会更方便

Id = this.getResources().getIdentifier("euro1", "drawable", this.getPackageName());

Id = R.drawable.euro1;

尽管。

于 2013-06-24T23:19:43.810 回答