निम्न स्निपेट गैलरी की सामग्री को पुनर्प्राप्त करता है और प्रत्येक छवि पथ को सरणी सूची के अंदर रखता है। तो फिर यह बेतरतीब ढंग से ArrayList अंदर पथ से एक का चयन और एक imageView
Handler handler = new Handler();
protected int counter = 0;
private ImageView mImageView;
private Bitmap currentBitmap = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.image);
mImageView = (ImageView) findViewById(R.id.imageView);
String[] projection = new String[]{
MediaStore.Images.Media.DATA,
};
Uri images = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
Cursor cur = managedQuery(images,
projection,
"",
null,
""
);
final ArrayList<String> imagesPath = new ArrayList<String>();
if (cur.moveToFirst()) {
int dataColumn = cur.getColumnIndex(
MediaStore.Images.Media.DATA);
do {
imagesPath.add(cur.getString(dataColumn));
} while (cur.moveToNext());
}
cur.close();
final Random random = new Random();
final int count = imagesPath.size();
handler.post(new Runnable() {
@Override
public void run() {
int number = random.nextInt(count);
String path = imagesPath.get(number);
if (currentBitmap != null)
currentBitmap.recycle();
currentBitmap = BitmapFactory.decodeFile(path);
mImageView.setImageBitmap(currentBitmap);
handler.postDelayed(this, 1000);
}
});
}
पुरस्कार के लिए इस तरह के नीचे Blackbelt के रूप में अपनी प्रतिक्रिया के लिए समय में उन सुनिश्चित करें के लिए संसाधनों के रूप में डाल दिया। अन्यथा गरीब प्रतिष्ठा बर्बाद हो जाएगी और कोई भी * उदास * लाभ नहीं उठाएगा। –
आप सही हैं, मैं –