ImageView returning as null in android -


so issue have set of data inside listview outputs onto page. able change image based on rating retrieved. reason when try set imageview variable , find id returns null. there way can retrieve other way?

if (jo.getstring("ratingvalue").contains("-1")) {                         listplaces.add(jo.getstring("businessname") + "\n" + jo.getstring("addressline1") + "\n"                                 + jo.getstring("addressline2") + "\n" + jo.getstring("addressline3") + "\n"                                 + jo.getstring("postcode") + "\nrating: exempt\ndated: "                                 + jo.getstring("ratingdate") + "\n");                     } else {                         if (jo.getstring("ratingvalue").contains("0")) {                             changeimg(0);                             system.out.println("result 0");                         } else if (jo.getstring("ratingvalue").contains("1")) {                             changeimg(1);                             system.out.println("result 1");                         } else if (jo.getstring("ratingvalue").contains("2")) {                             changeimg(2);                             system.out.println("result 2");                         } else if (jo.getstring("ratingvalue").contains("3")) {                             changeimg(3);                             system.out.println("result 3");                         } else if (jo.getstring("ratingvalue").contains("4")) {                             changeimg(4);                             system.out.println("result 4");                         } else if (jo.getstring("ratingvalue").contains("5")) {                             changeimg(5);                             system.out.println("result 5");                         } 

this if statements , here method change image

 private void changeimg(int img) {      final imageview imageview = (imageview)findviewbyid(r.id.icon);              system.out.println(imageview + "outside");             switch (img) {                 case 0:                     imageview.setimageresource(r.drawable.rating0);                 case 1:                     imageview.setimageresource(r.drawable.rating1);                 case 2:                     imageview.setimageresource(r.drawable.rating2);                 case 3:                     imageview.setimageresource(r.drawable.rating3);                 case 4:                     imageview.setimageresource(r.drawable.rating4);                 case 5:                     system.out.println(imageview + "inside");                     imageview.setimageresource(r.drawable.rating5);              } } 

without imageview statements works without changing image.

also add method called inside aysnctask class

thanks in advance.

<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <imageview     android:id="@+id/icon"     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:src="@drawable/rating0"/> <textview     android:id="@+id/data"     android:layout_width="wrap_content"     android:layout_height="wrap_content"/> </linearlayout> 

all ui related stuff must done @ ui/main thread, if want change image of imageview @ thread (for example, asynctask). should use

myactivity.this.runonuithread(new runnable(){     @override     public void run(){         // change ui here     } }); 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -