views:

51

answers:

0

I have a custom adapter for a list in my ListActivity in my Android app. I'm dynamically setting the background color of the current item that was clicked because I want to set the marquee of the TextView in the custom list item. This is how I'm doing this:

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {

    super.onListItemClick(l, v, position, id);

    this.currentPositionSelected = position;

    if (this.tempListItemView != null) {
        TextView tempTxtView = (TextView) tempListItemView.findViewById(R.id.txtArticleTitle);
        tempTxtView.setSelected(false);
        tempTxtView.setEllipsize(TruncateAt.END);
        this.tempListItemView.setBackgroundColor(Color.TRANSPARENT);
    }

    // Set marquee
    TextView tt = (TextView) v.findViewById(R.id.txtArticleTitle);

    v.setBackgroundDrawable(getResources().getDrawable(R.drawable.list_selector));

    tt.setEllipsize(TruncateAt.MARQUEE);
    tt.setSelected(true);
    tempListItemView = v;


}

This does work, however I have like 25 items in my list. When I scroll down after I have clicked an item and it highlights, many items are selected in the list and I didn't click them. After printing out the address location of the View that's passed in:

System.out.println("Addy: " + v.toString());

I see that all of the selected item have the same reference to the View passed in. This makes sense as to why others are selected. How can I set these behaviors for JUST the single item selected? My ListView also has a custom listSelector if that matters at all.

I'm pulling my hair out with this one...

Thanks so much!