image - Error in else value on android -


i want change visibility when special status

so else

else {   imageview image_a_wrong = (imageview)findviewbyid(r.id.imageview1); image_a_wrong.setvisibility(view.gone);  } 

but appear error on eclipse.

do know why ?

my imageview

<imageview         android:id="@+id/imageview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/quo100px"         android:visibility="gone" /> 

tks advance all

here complete file

package com.example.androidhive;

import java.util.arraylist; import java.util.hashmap; import java.util.list;

import org.apache.http.namevaluepair; import org.json.jsonarray; import org.json.jsonexception; import org.json.jsonobject;

import android.app.listactivity; import android.app.progressdialog; import android.content.intent; import android.os.asynctask; import android.os.bundle; import android.util.log; import android.view.view; import android.widget.adapterview; import android.widget.adapterview.onitemclicklistener; import android.widget.imageview; import android.widget.listadapter; import android.widget.listview; import android.widget.simpleadapter; import android.widget.textview;

public class quopapiercord extends listactivity {

  // progress dialog   private progressdialog pdialog;    // creating json parser object   jsonparser jparser = new jsonparser();    arraylist<hashmap<string, string>> productslist;    // url products list   private static string url_all_products_quo = >"http://192.168.1.81/php/android/get_all_quotidiens.php";    // json node names   private static final string tag_success = "success";   private static final string tag_products = "products";   private static final string tag_pid = "pid";   private static final string tag_name = "name";   private static final string tag_price = "price";   private static string tag_cu = "cu";    // products jsonarray   jsonarray products = null;    @override   public void oncreate(bundle savedinstancestate) {       super.oncreate(savedinstancestate);       setcontentview(r.layout.quotidiens);        // hashmap listview       productslist = new arraylist<hashmap<string, string>>();        // loading products in background thread       new loadallproducts().execute();        // listview       listview lv = getlistview();        // on seleting single product       // launching edit product screen       lv.setonitemclicklistener(new onitemclicklistener() {            @override           public void onitemclick(adapterview<?> parent, view view,                   int position, long id) {               // getting values selected listitem               string pid = ((textview) >view.findviewbyid(r.id.pid)).gettext()                       .tostring();                // starting new intent               intent in = new intent(getapplicationcontext(),                       editproductactivity.class);               // sending pid next activity               in.putextra(tag_pid, pid);                // starting new activity , expecting response               startactivityforresult(in, 100);           }       });    }    // response edit product activity   @override   protected void onactivityresult(int requestcode, int resultcode, intent data) {       super.onactivityresult(requestcode, resultcode, data);       // if result code 100       if (resultcode == 100) {           // if result code 100 received            // means user edited/deleted product           // reload screen again           intent intent = getintent();           finish();           startactivity(intent);       }    }    /**    * background async task load product making http request    * */   class loadallproducts extends asynctask<string, string, string> {        /**        * before starting background thread show progress dialog        * */       @override       protected void onpreexecute() {           super.onpreexecute();           pdialog = new progressdialog(quopapiercord.this);           pdialog.setmessage("loading products. please wait...");           pdialog.setindeterminate(false);           pdialog.setcancelable(false);           pdialog.show();       }        /**        * getting products url        * */       protected string doinbackground(string... args) {           // building parameters           list<namevaluepair> params = new arraylist<namevaluepair>();           // getting json string url           jsonobject json = jparser.makehttprequest(url_all_products_quo, >"get", params);            // check log cat json reponse           log.d("all products: ", json.tostring());            try {               // checking success tag               int success = json.getint(tag_success);                if (success == 1) {                   // products found                   // getting array of products                   products = json.getjsonarray(tag_products);                    // looping through products                   (int = 0; < products.length(); i++) {                       jsonobject c = products.getjsonobject(i);                        // storing each json item in variable                       string id = c.getstring(tag_pid);                       string name = c.getstring(tag_name);                       string price = c.getstring(tag_price);                       string cu = c.getstring(tag_cu);                       /////////////                       if (cu.equals("1")) {                           cu = "oui";                       } else {                           imageview image_a_wrong = (imageview) >findviewbyid(r.id.imageview1);                           image_a_wrong.setvisibility(view.gone);                       }                       // creating new hashmap                       hashmap<string, string> map = new >hashmap<string, string>();                        // adding each child node hashmap key => >value                       map.put(tag_pid, id);                       map.put(tag_name, name);                       map.put(tag_price, price);                       map.put(tag_cu, cu);                        // adding hashlist arraylist                       productslist.add(map);                   }               } else {                   // no products found                   // launch add new product activity                   intent = new intent(getapplicationcontext(),                           newproductactivity.class);                   // closing previous activities                   i.addflags(intent.flag_activity_clear_top);                   startactivity(i);               }           } catch (jsonexception e) {               e.printstacktrace();           }              return null;       }        /**        * after completing background task dismiss progress dialog        * **/         protected void onpostexecute(string file_url) {           // dismiss dialog after getting products           pdialog.dismiss();           // updating ui background thread           runonuithread(new runnable() {               public void run() {                   /**                    * updating parsed json data listview                    * */                   listadapter adapter = new simpleadapter(                           quopapiercord.this, productslist,                           r.layout.list_item, new string[] { >tag_pid,                                   tag_name, >tag_price, tag_cu},                           new int[] { r.id.pid, r.id.name, >r.id.price, r.id.cu });                   // updating listview                   setlistadapter(adapter);               }           });        }    } 

}

<?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"      android:padding="5px"     android:stretchcolumns="1">      <!-- product id (pid) - hidden - used pass other activity -->     <textview         android:id="@+id/pid"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:visibility="gone" />       <!-- name label -->     <textview         android:id="@+id/name"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingright="10px"          android:textsize="17sp"         android:layout_marginright="10px"         android:layout_weight="0.2"         android:textcolor="#fff"         android:gravity="left"  />      <!-- price label -->     <textview         android:id="@+id/price"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingright="5px"          android:textsize="17sp"         android:layout_marginright="5px"         android:layout_weight="0.2"         android:textcolor="#c00000"         android:gravity="left"         android:textstyle="bold"  />      <imageview         android:id="@+id/imageview1"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:src="@drawable/quo100px"/>       <textview         android:id="@+id/cu"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingright="5px"          android:textsize="17sp"         android:layout_marginright="5px"         android:layout_weight="0.2"         android:textcolor="#c00000"         android:gravity="left"         android:textstyle="bold"  />         <textview         android:id="@+id/mc"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingright="5px"          android:textsize="17sp"         android:layout_marginright="5px"         android:layout_weight="0.2"         android:textcolor="#c00000"         android:gravity="left"         android:textstyle="bold"  />        <textview         android:id="@+id/tel"         android:layout_width="fill_parent"         android:layout_height="wrap_content"         android:paddingright="5px"          android:textsize="17sp"         android:layout_marginright="5px"         android:layout_weight="0.2"         android:textcolor="#c00000"         android:gravity="left"         android:textstyle="bold"  />  </linearlayout> 

seeing error here, can't access ui (textview, edittext, imageview, etc) inside doinbackgroud. on either onpostexecute or onprogressupdate method

edit: change

if (cu.equals("1")) {    cu = "oui"; }  else {    imageview image_a_wrong = (imageview) findviewbyid(r.id.imageview1);    image_a_wrong.setvisibility(view.gone); } 

to

if (cu.equals("1")) {    cu = "oui"; }  else {    cu = "pas"; } 

then add onpostexecute()

edit 2: seeing code i've narrowed error. above code must like

declare string cu globally , try follwing

imageview image_a_wrong = (imageview) findviewbyid(r.id.imageview1); if(cu.equals("pas")) {     image_a_wrong.setvisibility(view.gone); } else {     image_a_wrong.setvisibility(view.gone); } 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -