在Android应用程序显示图片 [英] Show picture in android app

查看:170
本文介绍了在Android应用程序显示图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个测验的应用程序与一个问题,三个答案。

I've written a quiz app with one question and three answers.

的问题和答案都保存在一个 Frage 对象。例如:

The questions and answers are saved in a Frage object. For example:

Frage f6 = new Frage(7, "Welche Notrufnummer hat die Rettung in Österreich?", 
                     "166", "144", "110", "144", "bronze");

现在我想延长整个事情,我可以再次显示一张图片,一问这个图片和三个答案。
什么是实施的最佳方式?我如何保存在我的应用程序的图片?

Now I want to extend the whole thing that I can show a picture, a question to this pictures and three answers again. What is the best way to implement that? How can I save pictures in my app?

编辑:作为I'm在Android的初期发展中,我不确定如何连接的图片,我的问题。
最好的办法可能是使用命名此时,相应的问题ID的图片,对吧?

As I´m on the very beginning of Android developing, I´m not sure how to connect the picture and my questions. The best way might be to name the pictures with the id of the appropiate question, right?

推荐答案

您保存您的照片在你的资产或绘制文件夹,并通过

You save your picture in your asset or drawable folder and show them via

绘制对象:

ImageView iv = new ImageView(this); // (ImageView) findViewById(R.drawable.imageview);
iv.setImageResource( R.drawable.picture );

资产:

try 
{
    // get input stream
    InputStream ims = getAssets().open("avatar.jpg");
    // load image as Drawable
    Drawable d = Drawable.createFromStream(ims, null);
    // set image to ImageView
    iv.setImageDrawable(d);
}
catch(IOException ex) 
{
    ex.printStackTrace();
}

在你的情况可能节省资源ID在你的Frage的对象,并给它你imageviee。

In your case maybe save the resource id in your "Frage" object and give it your imageviee.

Frage f6 = new Frage(7, "Welche Notrufnummer hat die Rettung in Österreich?", 
                     "166", "144", "110", "144", "bronze",R.drawable.austria_emergency_call);

besten格鲁斯

besten Gruß

这篇关于在Android应用程序显示图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆