android - Change the image in ListView automatically according to the conditions -
It can be a copy of the question just a few days back:. I got an answer, which completely fulfilled my requirement but not completely. I am posting it again because I want you people's attention. Sorry for that. In the activity class.
Try {training.setTime (New Simple Format ("MM-dd-yyyy HH: mm") .pars (strDateTime)); Long distance = training .getTimeInMillis () - now. GetTimeInMillis (); If (difference <15 * 60 * 1000) {// atleast 15 minutes training adapter ViewHolder.status = 1; TrainingAdapter.notifyDataSetChanged (); Intention = Intention = new idea (getApplicationContext (), TRAINY LISTACTIVITY.Class); MainActivity.this.startActivity; End(); } And {training adapter. ViewHolder.status = 1; Toast. GetApplicationContext, "Training Begins" + "" + Training Startdate + "+ + Training Startup, Toast. LNNHHORAR). Show (); }} Hold (java.text.ParseException e) {e.printStackTrace (); } in the adapter category; see public getView (see the status of int, seeview view, view group guardian) {seeholder holder; Int tmp_status = 0; If (convertView == faucet) {convertView = mInflater.inflate (R. layout. Training adapter, blank); Holder = new viewholder (); Holder.txtName = (TextView) Convertview. FindViewById (R.id.training_title); Holder.trainingDetails = (TextView) Convertview. FindViewById (R.id.training_dtls); Holder Lock image = (ImageView) Convertview. FandviewIID (RID lock image); ConvertView.setTag (holder); } And {holder = (seeholder) ConvertView.gettag (); Tmp_status = seeholder.tastas; } Holder.txtName.setText (TrainingList.Gate (status) .getTitle ()); Holder.trainingDetails.setText ("in" + trainingingsList.get (position) .getLocation () + "on" + trainingingsList.get (status) .getDate () + "at" + trainingList.get (status) .getStartTime () + "-" + TrainingList.Gate (status) .tetendime (+) "by" + traininglist.gate (status) .getTrainer ()); If (tmp_status == 0) {System.out.println (tmp_status); Holder.lockImage.setBackgroundResource (R.drawable.unlock); } And if (tmp_status == 1) {System.out.println (tmp_status); Holder.lockImage.setBackgroundResource (R.drawable.lock); } Return Convertview; } Fixed class viewer {text visual training; description; TextView txtName; Image view lock image; Public static completion status; } Here, image int tmp_status = 0; is changing according to the value. If I initialize the value for 1, then only it gives another image but on all the list views. In the activity category, you can see that the conditions of each list are different, i.e. the intention of any other activity. Can you know where the problem is.
Remove the status variable from the viewer. ViewHolder is for ideas only. You have to keep the situation flat for each line. It can be a list of integer or Pozzo's list.
public view getView (see the status of int, viewview view, view group guardian) {seeholder holder; Int tmp_status = 0; If (convertView == faucet) {convertView = mInflater.inflate (R. layout. Training adapter, blank); Holder = new viewholder (); Holder.txtName = (TextView) Convertview. FindViewById (R.id.training_title); Holder.trainingDetails = (TextView) Convertview. FindViewById (R.id.training_dtls); Holder Lock image = (ImageView) Convertview. FandviewIID (RID lock image); ConvertView.setTag (holder); } And {holder = (seeholder) ConvertView.gettag (); } Tmp_status = listOfStatuses.get (status); Holder.txtName.setText (trainingingsList.get (status) .getTitle ()); Holder.trainingDetails.setText ("in" + trainingingsList.get (position) .getLocation () + "on" + trainingingsList.get (status) .getDate () + "at" + trainingList.get (status) .getStartTime () + "-" + TrainingList.Gate (status) .tetendime (+) "by" + traininglist.gate (status) .getTrainer ()); If (tmp_status == 0) {System.out.println (tmp_status); Holder.lockImage.setBackgroundResource (R.drawable.unlock); } And if (tmp_status == 1) {System.out.println (tmp_status); Holder.lockImage.setBackgroundResource (R.drawable.lock); } Return Convertview; } Fixed class viewer {text visual training; description; TextView txtName; Image view lock image; }
Comments
Post a Comment