android - Starting a method in a thread, then changing the variables and starting a second thread of that method -


im trying use setlv1sunflower() start new thread, shows plant grow ever player picks. after pressing seed button, player picks placeholder* plant start grow. have each plant position eg placeholder1(), placeholder2() , on.

//place holder onclick shows info on plant or if watermodeon true shows found animal or no animal     public void placeholder1(view view){         if (watermodeon == false){             toast.maketext(getapplicationcontext(), placeholder1toastmsg, toast.length_long).show();         }         if (seedmodeon == true){             showseedmenu();             selectedplantimage = placeholder1image;             selectedplanttoastmsg = placeholder1toastmsg;             selectedplantfoundanimal = placeholder1foundanimal;             selectedplantfullygrown = plant1fullygrown;          }         else{             showfoundanimaldialog();         }     } 

then starts whichever plant pic, atm have 1 set up

//sets new plant place holder     public void showseedmenu(){          final charsequence[] items = {"lv1 sunflower", "lv1 daisy", "lv1 violet"};          alertdialog.builder builder = new alertdialog.builder(this);         builder.settitle("pick seed");         builder.setitems(items, new dialoginterface.onclicklistener() {             public void onclick(dialoginterface dialog, int item) {                  if (item == 0){                      lv1seeds.setlv1sunflower();                   }                  seedmodeon = false;             }         });         alertdialog alert = builder.create();         alert.show();     } 

this lv1seeds.class

package com.gameplay.mysticgarden;  import android.app.activity; import android.view.view;      //level 1 seed values place holders     public class lv1seeds extends activity {    //ints loops     final static int = 1;     final static int b = 2;      //lv1 sunflower values     public static void setlv1sunflower(){          gamescreen.selectedplantfoundanimal = false;           gamescreen.selectedplantimage.setimageresource(r.drawable.plant_stage1);              gamescreen.selectedplantimage.setvisibility(view.visible);          //first thread start         /*runnable runnable = new runnable() {               @override               public void run() {*/               //2 lines of test code              new thread(new runnable() {                         public void run() {                   //udate ui stage 1 of plant , sets toast msg while plant seedling                   while (a < b){                       //sets animal gone when loop starts again                       gamescreen.selectedplantfoundanimal = false;                     //if plant not grown update ui , toast seedling stage                         if (gamescreen.selectedplantfullygrown == false){                             gamescreen.selectedplanttoastmsg = "lv1 seedling sunflower \\(sunnious brightium\\) \nwill attract bee's!";                         }                   //wait 20 seconds                   //change of values makes seedling stage last longer                   try {                     thread.sleep(1000 * 10 * 1);                   } catch (interruptedexception e) {                     e.printstacktrace();                   }                    //update ui stage 2 of plant                   gamescreen.selectedplantimage.post(new runnable() {                     @override                     public void run() {                         //if plant not grown update ui , toast stage 2                         if (gamescreen.selectedplantfullygrown == false){                         gamescreen.selectedplantimage.setimageresource(r.drawable.plant_stage_2);                         gamescreen.selectedplanttoastmsg = "lv1 half grown sunflower \\sunnious brightium\\ \nwill attract bee's!";                         }                     }                   });                   //wait 20 seconds                   //change of value makes stage 2 last longer                   try {                         thread.sleep(1000  * 10 * 1);                       } catch (interruptedexception e) {                         e.printstacktrace();                       }                    //update ui grown plant                   gamescreen.selectedplantimage.post(new runnable() {                      @override                      public void run() {                         //if plant not yet grown update ui , toast grown plant , sets plantfullygrown true                         if (gamescreen.selectedplantfullygrown == false){                         gamescreen.selectedplantimage.setimageresource(r.drawable.flower_daisy);                         gamescreen.selectedplanttoastmsg = "lv1 sunflower \\(sunnious brightium\\) \nwill attract bee's!";                         gamescreen.selectedplantfullygrown = true;                         }                         //used when plant grown                         else{                             gamescreen.selectedplanttoastmsg = "lv1 sunflower \\(sunnious brightium\\) \nwill attract bee's!";                             }                         }                       });                       //wait 20 seconds                       //change of values make time longer before animal comes, once plant grown                       try {                             thread.sleep(1000  * 10 * 1);                           } catch (interruptedexception e) {                             e.printstacktrace();                           }                     //sets animal in garden                    gamescreen.selectedplantimage.post(new runnable() {                       @override                       public void run() {                           gamescreen.selectedplantfoundanimal = true;                       }                    });                    //animal stays time period                    //change of value makes animal stay longer                         try {                               thread.sleep(1000  * 10 * 1);                             } catch (interruptedexception e) {                               e.printstacktrace();                             }                    }               }      }).start();           //end of sunflower()             }      //end of class       } 

when second plant started, setlv1sunflower() doesnt start new instance of method pland 1 stop doing , second plant carries on first plant in method

this problem.....the first plant should keep growing, while second plant starts off new

xml gamescreen is

<?xml version="1.0" encoding="utf-8"?> <relativelayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="@drawable/bg_sun_1" >      <button         android:id="@+id/waterbutton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentbottom="true"         android:layout_alignparentleft="true"         android:background="@drawable/water_drop" />      <textview         android:id="@+id/waterpoints"         android:layout_width="300sp"         android:layout_height="wrap_content"         android:layout_alignbaseline="@+id/waterbutton"         android:layout_alignbottom="@+id/waterbutton"         android:layout_alignparentleft="true"         android:layout_marginleft="176dp"         android:text="large text"         android:textappearance="?android:attr/textappearancelarge"         android:textsize="36sp" />      <imageview         android:id="@+id/placedholder1image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_toleftof="@+id/placedholder2image"         android:background="@drawable/blackspaceflower"         android:onclick="placeholder1"         android:visibility="invisible" />      <imageview         android:id="@+id/placedholder2image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_toleftof="@+id/placedholder3image"         android:background="@drawable/blackspaceflower"         android:onclick="placeholder2"         android:visibility="invisible" />      <imageview         android:id="@+id/placedholder3image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centerinparent="true"         android:background="@drawable/blackspaceflower"         android:onclick="placeholder3"         android:visibility="invisible" />      <imageview         android:id="@+id/placedholder4image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_torightof="@+id/placedholder3image"         android:background="@drawable/blackspaceflower"         android:onclick="placeholder4"         android:visibility="invisible" />      <imageview         android:id="@+id/placedholder5image"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_centervertical="true"         android:layout_torightof="@+id/placedholder4image"         android:background="@drawable/blackspaceflower"         android:onclick="placeholder5"         android:visibility="invisible" />      <button         android:id="@+id/seedbutton"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignparentleft="true"         android:layout_alignparenttop="true"         android:layout_marginleft="36dp"         android:layout_margintop="22dp"         android:onclick="showselectplantdialog"         android:text="@string/seeds" />  </relativelayout> 

i hope can please me....your time appreciated


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -