I have a gallery viewer (following this tutorial) and I need to hide the thumbnails after 5 seconds, and show them again if the user touches the screen. Basically, when the thumbnails are hidden, it'd only be shown the image that has been selected.
My code is the following:
package com.xs2theworld.sundio;
import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class GalleryView extends Activity {
Integer[] pics = { R.drawable.antartica1, R.drawable.antartica2, R.drawable.antartica3, R.drawable.antartica4, R.drawable.antartica5, R.drawable.antartica6, R.drawable.antartica7,
R.drawable.antartica8, R.drawable.antartica9, R.drawable.antartica10 };
ImageView imageView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.gallery_view_layout);
Gallery ga = (Gallery) findViewById(R.id.GalleryThumbnails);
ga.setAdapter(new ImageAdapter(this));
imageView = (ImageView) findViewById(R.id.GalleryImage);
// We show the first image when creating the view gallery
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(pics[0]);
ga.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(pics[arg2]);
}
});
}
public class ImageAdapter extends BaseAdapter {
private Context ctx;
int imageBackground;
public ImageAdapter(Context c) {
ctx = c;
TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
ta.recycle();
}
public int getCount() {
return pics.length;
}
public Object getItem(int arg0) {
return arg0;
}
public long getItemId(int arg0) {
return arg0;
}
public View getView(int arg0, View arg1, ViewGroup arg2) {
ImageView iv = new ImageView(ctx);
iv.setImageResource(pics[arg0]);
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setLayoutParams(new Gallery.LayoutParams(200, 120));
iv.setBackgroundResource(imageBackground);
return iv;
}
}
}
How could I do this?
Thanks a lot in advance!
use TimerTask to hide the Gallery at scheduled time after 5 seconds...
Timer timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask()
{
public void run()
{
//Do your task here
}
},delay,period);
Or you can use this ...
View v = new View(this);
v.postDelayed(new Runnable(){
public void run() {
// TODO Auto-generated method stub
// Hide your Gallery here
}
}, (long) 5000.0);
Hope it will Help you.