【发布时间】:2014-05-26 10:09:51
【问题描述】:
我是 android 开发的新手,我正在尝试显示一些小图像(小国旗),每个图像旁边都有一些描述文本。 我正在做的是创建一个连接到互联网的异步作业来检索我需要的信息并在一个类中填充一些变量,最后它返回这个类的一个对象。 函数 onPostExecute
protected void onPostExecute(String result) {
System.out.println(xmlData.getCurrency("USD"));
try {
activReg.getResult(xmlData);
} catch (Exception e) {
// TODO: handle exception
System.out.println("MESSAGE GET RESULT"+e.getMessage());
}
}
MainActivity 中的 getResult 函数看起来像
public void getResult(Currency xmlObj){
LinearLayout right = new LinearLayout(this);
Resources resource = getResources();
ImageView imgUsd = (ImageView) this.findViewById(R.id.usd);
final Drawable drawable = imgUsd.getDrawable();
TextView res = new TextView(this);
imgUsd.setImageDrawable(drawable);
res.setText("EUR=>USD: "+Double.toString(xmlObj.getCurrency("USD")));
//res.setText("EUR=>GBP: "+Double.toString(xmlObj.getCurrency("GBP")));
setContentView(res);
}
现在你可以看到我把所有东西都搞砸了,尝试了很多无论如何都不起作用的东西。所以我想要实现的是有一个xmlObj.getCurrency("USD")、xmlObj.getCurrency("GBP") 等列表,旁边有一个小标志图像。当然,如果我不止一个使用 setText,最后一个会覆盖前一个,这就引出了我的两个问题:
- 如何在布局中添加更多文本?
- 如何添加在主 xml 布局中定义(或未定义)的图像?
供您参考,布局是LinearLayout,我也尝试以这种方式包含图像:
<ImageView
android:id="@+id/usd"
android:layout_width="59dp"
android:layout_height="40dp"
android:layout_gravity="fill_vertical"
android:src="@drawable/usd" />
在xml中。
【问题讨论】:
标签: android image text android-asynctask