I am new to android and I am working in an application that want to swipe my layouts. Is it possible to bind layouts to android widget Gallery. Or please advice me the best practice to swipe my layouts in android.
Please help me with a valid link if possible
Thanks in advance.
My main class
public class GalleryTestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery) findViewById(R.id.gallery);
gallery.setAdapter(new ImageAdapter(this));
}
}
My base class
public class ImageAdapter extends BaseAdapter {
int mGalleryItemBackground;
private Activity mContext;
private Gallery mGallery;
private Integer[] mImageIds = {
R.layout.instruction,
R.layout.instruction2
};
public ImageAdapter(Activity c)
{
mContext=c;
TypedArray attr = mContext.obtainStyledAttributes(R.styleable.HelloGal999lery);
mGalleryItemBackground = attr.getResourceId(
R.styleable.HelloGal999lery_android_galleryItemBackground, 100);
attr.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
//Help me here
View rowView = convertView;
if(rowView==null)
{
LayoutInflater inflater = mContext.getLayoutInflater();
rowView = inflater.inflate(mImageIds[position], null, true);
}
return rowView;
}
}
You may use
Gallery.or there is new widget
ViewPagerin android support package.Here is nice tutorial about
ViewPagerThis is also a good repository about
ViewPagerusage.