Images in sequence - Android

myst

New Member
I have a question about using Url in the xml file - how to change it to select images from the local memory of the app? I am adding my Java code for using the xml file for the location of the files but using the Url of the images. Basically i need to change images when an option of choices is selected. \[code\]private ImageSwitcher mAnswerImage;mAnswerImage = (ImageSwitcher) findViewById(R.id.ImageSwitcher_AnswerImage);mAnswerImage.setFactory(new MyImageSwitcherFactory());ImageSwitcher questionImageSwitcher = (ImageSwitcher) findViewById(R.id.ImageSwitcher_QuestionImage); Drawable image = getQuestionImageDrawable(nextQuestionNumber); questionImageSwitcher.setImageDrawable(image); private String getQuestionImageUrl(Integer questionNumber) { String url = null; Question curQuestion = (Question) mQuestions.get(questionNumber); if (curQuestion != null) { url = curQuestion.mImageUrl; } return url;}private Drawable getQuestionImageDrawable(int questionNumber) { Drawable image; URL imageUrl; try { // Create a Drawable by decoding a stream from a remote URL imageUrl = new URL(getQuestionImageUrl(questionNumber)); InputStream stream = imageUrl.openStream(); Bitmap bitmap = BitmapFactory.decodeStream(stream); image = new BitmapDrawable(getResources(), bitmap); } catch (Exception e) { Log.e(DEBUG_TAG, "Decoding Bitmap stream failed"); image = getResources().getDrawable(R.drawable.noquestion); } return image;}private class MyImageSwitcherFactory implements ViewSwitcher.ViewFactory { public View makeView() { ImageView imageView = (ImageView) LayoutInflater.from( getApplicationContext()).inflate( R.layout.image_switcher_view, mQuestionImage, false); return imageView; }} private class Question { @SuppressWarnings("unused") int mNumber; String mText; String mImageUrl; public Question(int questionNum, String questionText, String questionImageUrl) { mNumber = questionNum; mText = questionText; mImageUrl = questionImageUrl; }}\[/code\]
 
Back
Top