Reputation: 6181
I am trying to make a Gallery that uses TextViews instead of ImageViews, but I cannot seem to make a working adapter. How can I use an adapter to fill the Gallery with TextViews?
Upvotes: 0
Views: 278
Reputation: 3550
Just extend BaseAdapter like so:
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;
}
and assign it to the gallery using:
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new GalleryTextAdapter(this));
Upvotes: 2