You only ever setting the color to be pink. You need to set the color to be not-pink as well, for cases where the row is recycled, was pink, and now no longer is supposed to be pink.
On Sat, Sep 1, 2012 at 7:10 AM, LiTTle <[email protected]> wrote: > Hi everyone, > > I am trying 4 days to solve this problem. I am trying to create the > following feature: > I have a ListView that the user can select an item. When the user selects > the item the text will turn to pink. The ListView shows 6 items at once. You > have to scroll to see other 6 and go on. > But there is a problem: > When i scroll the ListView the item No8, No15,... are pink too! > Any help, ideas (even if you think you are wrong) are welcomed. I am > freaking out more and more every day. > Thanks a lot for your time spent reading my issue! > > Here is the code inside for my adapter: > //////////////////////////////////////////////// > public class MyListAdapter extends ArrayAdapter<String> { > > private Context ctx; > private String[] values; > private ArrayList<String> mData =new ArrayList<String>(); > private ViewHolder holder=null; > private LayoutInflater inflater; > public MyListAdapter(Context context, int textViewResourceId, String[] > values) { > super(context, textViewResourceId, values); > > ctx = context; > inflater = (LayoutInflater) ctx > .getSystemService(Context.LAYOUT_INFLATER_SERVICE); > this.values = values; > for (int i = 0; i < values.length; i++) { > addItem(values[i]); > } > } > public void addItem(final String item) { > mData.add(item); > notifyDataSetChanged(); > } > @Override > public String getItem(int position) { > return mData.get(position); > } > > @Override > public long getItemId(int position) { > return position; > } > > @Override > public int getCount() { > // TODO Auto-generated method stub > return mData.size(); > } > > /* (non-Javadoc) > * @see android.widget.ArrayAdapter#getView(int, android.view.View, > android.view.ViewGroup) > */ > @Override > public View getView(int position, View convertView, ViewGroup parent) { > > if(convertView==null){ > convertView = inflater.inflate(R.layout.list_item, parent, false); > holder = new ViewHolder(); > holder.textView = > (TextView)convertView.findViewById(R.id.item_textView); > convertView.setTag(holder); > } > else{ > holder = (ViewHolder)convertView.getTag(); > } > holder.textView.setText(mData.get(position)); > holder.textView.setOnClickListener(new OnClickListener() { > > @Override > public void onClick(View view) { > for(int i=0; i<getCount(); i++){ > } > ((ViewHolder)view.getTag()).textView.setTextColor(ctx.getResources(). > getColor(R.color.pink)); > } > }); > return convertView; > } > public static class ViewHolder { > public TextView textView; > } > > } > /////////////////////////////////////// > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to [email protected] > To unsubscribe from this group, send email to > [email protected] > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy _The Busy Coder's Guide to Android Development_ Version 4.1 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

