Я попытался понять, почему моя переменная result
равна нулю? Я проверяю его отладки, но я не понимаю, почему .. Я не вижу своего ImageView в устройстве А вот мой код:Почему я не вижу ImageView на своем устройстве?
public class ClassicView extends Activity {
private Content content;
public LinearLayout view;
ClassicView classicView;
JSONParser jParser;
Context context;
private Bitmap bitmap;
private ImageView downloadedImg;
private ProgressDialog simpleWaitDialog;
//RelativeLayout mainLayout;
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(new ViewGroup.MarginLayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT));
public ClassicView() {
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
JSONParser jParser = null;
try {
jParser = new JSONParser("Json.txt");
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
content = (Content)getIntent().getSerializableExtra("CONTENT");
//this.setClassicLabel(jParser.getContentViewWithId(content.getElemView()).getJSONArray("Label"));
//(jParser.getContentViewWithId(content.getElemView()).getJSONArray("Img"));
try {
this.setClassicImg();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void setClassicLabel(JSONArray listLabel) throws JSONException {
RelativeLayout rl = new RelativeLayout(this);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
setContentView(rl);
for (int i = 0; i < listLabel.length(); i++) {
TextView tv = new TextView(this);
tv.setText(listLabel.getJSONObject(i).getString("text"));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (metrics.widthPixels * listLabel.getJSONObject(i).getDouble("size_x")), (int) (metrics.heightPixels * listLabel.getJSONObject(i).getDouble("size_y")));
params.leftMargin = (int) (metrics.widthPixels * listLabel.getJSONObject(i).getDouble("position_x"));
params.topMargin = (int) (metrics.heightPixels * listLabel.getJSONObject(i).getDouble("position_y"));
rl.addView(tv, params);
}
}
public void setClassicImg() throws JSONException, IOException, MalformedURLException {
RelativeLayout rl2 = new RelativeLayout(this);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
setContentView(rl2);
ImageView downloadedImg = new ImageView(this);
new DownloadImageTask(downloadedImg).execute("http://felicita-pizzeria.fr/images/logo.png");
}
/* To Load Image */
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> {
ImageView myimage;
public DownloadImageTask(ImageView bmImage) {
this.myimage = bmImage;
}
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
mIcon11 = BitmapFactory.decodeStream(in);
} catch (Exception e) {
Log.e("Error", e.getMessage());
e.printStackTrace();
}
return mIcon11;
}
protected void onPostExecute(Bitmap result) {
myimage.setImageBitmap(result);
}
}`
Кто-нибудь может мне помочь, пожалуйста? спасибо
я думаю, что вы не findviewById() для ImageView которым вы передаете в качестве параметра –
Вы нашли ImageView в (скачалImg) в вашем макете? - ImageView скачалImg = (ImageView) rl2.findViewById (R.id.downloaded_image)? –
где вы создаете downloadImg ImageView? –