My lines have a button that has its own click listener installed in my getView adapter. I can distinguish between button clicks and actual row element clicks using android: descendantFocusability = "blocksDescendants" in the parent line.
When I click the button, it sets the button background correctly, my problem is that I am browsing the list, setting it for different lines. I assume that their problem is somewhere with the processing of views.
Here is my code:
@Override public View getView(int position, View convertView, ViewGroup parent){ if(convertView == null){ holder = new ViewHolder(); convertView = inflater.inflate(R.layout.todays_sales_favorite_row, null); holder.favCatBtn = (Button)convertView.findViewById(R.id.favCatBtn); convertView.setTag(holder); } else { holder = (ViewHolder)convertView.getTag(); } holder.favCatBtn.setTag(position); holder.favCatBtn.setOnClickListener(this); return convertView; } @Override public void onClick(View v) { int pos = (Integer) v.getTag(); Log.d(TAG, "Button row pos click: " + pos); RelativeLayout rl = (RelativeLayout)v.getParent(); holder.favCatBtn = (Button)rl.getChildAt(0); holder.favCatBtn.setBackgroundResource(R.drawable.icon_yellow_star_large); }
So if I press the button at position 1, the background of the button will change as it should. But then when I scroll through the list, random other buttons are also set. Then sometimes, when I scroll back to position 1, the background of the button returns to the original again.
What am I missing here? I know that I am here, just something secondary that I do not do.
askilondz
source share