Note that there are some explanatory texts on larger screens.

plurals
  1. POListView's ImageView onClick changing other rows also
    primarykey
    data
    text
    <p>I have a <code>ListView</code>. There is an <code>ImageView</code> in the row of the ListView. I have attached onClick attribute to the ImageView and my onClick function is</p> <pre><code>public void alarmClick(View v) { ImageView bell = (ImageView)v.findViewById(R.id.mEventImage); bell.setImageResource(R.drawable.bell_on); if(bell.getTag() == null) { bell.setImageResource(R.drawable.bell_on); bell.setTag(R.drawable.bell_on); } else if((Integer)bell.getTag() == R.drawable.bell_on) { bell.setImageResource(R.drawable.bell_off); bell.setTag(R.drawable.bell_off); } else { bell.setImageResource(R.drawable.bell_on); bell.setTag(R.drawable.bell_on); } } </code></pre> <p>I am trying to toggle the <code>ImageView</code> source but when i click the <code>ImageView</code> many other rows <code>ImageView</code> which are not on the screen at that time are also toggled. This is may be because the views are recycled in the <code>ListView</code>. Any suggestions how to do for each unique row.</p> <p>Adapter Class</p> <pre><code>package com.example.drawer; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; public class EventAdapter extends ArrayAdapter&lt;EventList&gt; { Context context; ArrayList&lt;EventList&gt; data; int layoutResourceId; public EventAdapter(Context context, int textViewResourceId, ArrayList&lt;EventList&gt; data) { super(context, textViewResourceId, data); this.context = context; this.data = data; this.layoutResourceId = textViewResourceId; // TODO Auto-generated constructor stub } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; EventHolder holder = null; if(row == null) { LayoutInflater inflator = ((Activity)context).getLayoutInflater(); row = inflator.inflate(layoutResourceId, parent, false); holder = new EventHolder(); holder.coord = (TextView)row.findViewById(R.id.eventCoor); holder.icon = (ImageView)row.findViewById(R.id.icon); holder.eventName = (TextView)row.findViewById(R.id.eventNam); holder.location = (TextView)row.findViewById(R.id.eventLoc); holder.time = (TextView)row.findViewById(R.id.eventTime); row.setTag(holder); } else { holder = (EventHolder)row.getTag(); } EventList listItem = data.get(position); ImageHelper imageHelper = new ImageHelper(); Bitmap icon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ipl); Bitmap newIcon = imageHelper.getRoundedCornerBitmap(icon, 200); holder.coord.setText(listItem.coord); holder.eventName.setText(listItem.eventName); holder.location.setText(listItem.location); holder.time.setText(listItem.time); holder.icon.setImageBitmap(newIcon); holder.id = listItem.id; holder.day = listItem.day; //Log.d("ListView", "Executed"); return row; } static class EventHolder { ImageView icon; TextView eventName; TextView location; TextView time; TextView coord; int id; int day; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload