我想以編程方式添加視圖到ViewFlipper:創建ImageView的自定義視圖,的AsyncTask不工作
flipper.addView(anEpisode(name, null, description), i);
我的方法是:
public View anEpisode(String n, String i, String d){
View v;
LayoutInflater inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(R.layout.episodedescription, null);
TextView nameOfEpisode = (TextView) v.findViewById(R.id.episodedescriptionname);
ImageView imageOfEpisode = (ImageView) v.findViewById(R.id.episodedescriptionimage);
TextView descriptionOfEpisode = (TextView) v.findViewById(R.id.episodedescriptiondescription);
nameOfEpisode.setText(n);
descriptionOfEpisode.setText(d);
createUrlImage(imageOfEpisode, i);
return v;
}
和createUrlImage是:
private class CreateImage extends AsyncTask<String, Void, Drawable> {
ImageView image;
public CreateImage(ImageView img) {
image = img;
}
protected void onPreExecute() {
}
protected Drawable doInBackground(String... urls) {
InputStream is;
Drawable d = null ;
try {
is = (InputStream)new URL(urls[0]).getContent();
d = Drawable.createFromStream(is, "Image");
return d;
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return d;
}
protected void onPostExecute(Drawable d) {
image.setBackgroundDrawable(d);
}
}
public void createUrlImage(ImageView img, String url){
new CreateImage(img).execute(url);
}
事情是:它根本不顯示圖像,所以我不知道該怎麼做。
您可以跟蹤您的代碼並查看計算機的功能。 – Snicolas
我該怎麼做?我只知道如何使用debuger。 – Tsunaze
ResourceType:資源不包含資源編號爲0x7f的包....所有頁面都有此行。 – Tsunaze