我正在尝试创建一个使用TextViews而不是ImageViews的Gallery,但我似乎无法制作一个有效的适配器。如何使用适配器用TextViews填充图库?
答案 0 :(得分:2)
像这样扩展BaseAdapter:
public class GalleryTextAdapter extends BaseAdapter{
Context context;
GalleryTextAdapter(Context context){
this.context = context;
}
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater li = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = li.inflate(R.layout.mylayout, null);
TextView tv = (TextView) convertView.findViewById(R.id.mylayout_text);
tv.setText("some text");
return convertView;
}
并使用以下内容将其分配到图库:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new GalleryTextAdapter(this));