Android:用文本视图填充图库

Android:用文本视图填充图库,android,Android,我试图制作一个使用文本视图而不是图像视图的图库,但我似乎无法制作一个工作适配器。如何使用适配器在多媒体资料中填充文本视图?只需像这样扩展BaseAdapter: public class GalleryTextAdapter extends BaseAdapter{ Context context; GalleryTextAdapter(Context context){ this.context = context; } public View g

我试图制作一个使用文本视图而不是图像视图的图库,但我似乎无法制作一个工作适配器。如何使用适配器在多媒体资料中填充文本视图?

只需像这样扩展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));

@不,不要那样做,这是错误的。A)您想返回包含TextView的视图,因此返回
convertView
,或B)您想返回TextView,因此您应该膨胀TextView并返回该视图。画廊不会回收视图,因此convertView始终为空,这正是我想在评论中说的。当然你说的绝对正确。我明白了。谢谢你的洞察力。