2016-10-27 4 views
0

私はアイテムを表示するためにgridViewを使用しています。すべてがOKですが、6つのアイテムやスクロールの後にいくつかのアイテムが繰り返されます。GridView CustomGrid Adapterはアイテムを繰り返します

だから私はconvertItemがnullでない場合に行うべきことがあると思います。しかし、私は、次の項目

いくつかのショートコード

をロードする方法:

public CustomGridAdapter(Context context, ArrayList<Event> finalResult, double latitude, double longitude) { 

    this.posLatitude = latitude; 
    this.posLongitude = longitude; 

    this.context = context; 
    this.gridValues = finalResult; 
    this.app = new Application(context); 
} 


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

@Override 
public Object getItem(int position) { 
    return null; 
} 

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

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

    // LayoutInflator to call external grid_item.xml file 
    LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

    View gridView; 

    if (convertView == null) { 

     gridView = new View(context); 

     gridView = inflater.inflate(R.layout.grid_item, null); 

     event = gridValues.get(position); 

    } else { 
     gridView = convertView; 
    } 
    return gridView; 
} 

答えて

1

ConvertViewは定義が再利用されることです。ビュー項目の値を変更して膨らませたり、設定してください。

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

// LayoutInflator to call external grid_item.xml file 
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); 

View gridView; 

if (convertView == null) { 

    gridView = inflater.inflate(R.layout.grid_item, null); 

} else { 
    gridView = convertView; 
} 

event = gridValues.get(position); 
// TODO: set view values based on this event 

return gridView; 
} 
+0

いいえ、私はevent_name =(TextView)を設定していません。gridView.findViewById(R.id.name);イベント名.setText(event.Name);私は間違ったビューを取得する – Fesco

+0

あなたのコードのより完全なビューがさらに答える必要があります。 – PSchuette

+0

私の誤ったerverthingは大丈夫ですありがとう – Fesco

関連する問題