1

Sorry if this is answered already, but I can't find anything and I can't specify my search very well. I have a list view in Fragment which uses an adapter to populate it, and I want the list view item rows, to get highlighted for a second when they get clicked, and I want them to get highlighted for just half a second then get back to normal (basically like a feedback that the item row is clicked), like the default call log works in the phone app. My adapter is exending ArrayAdapter. Any ideas?

EDIT: Here's the adapter getView()

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
        holder = new ViewHolder();
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    CallStats call = callsArray.get(position);
    convertView = inflater.inflate(R.layout.item_row_call, null);
    initializeViews(holder, convertView);
    setViewsEntries(holder, call);
    convertView.setTag(holder);
    return convertView;
}
Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81

2 Answers2

0

You can use "setSelector" like :

listView.setSelector(android.R.color.black);
Aparupa Ghoshal
  • 309
  • 2
  • 10
  • you have to add this line just after: listView.setAdapter(adapter); – Aparupa Ghoshal Feb 19 '14 at 10:39
  • that works when I removed the background of the item_row.xml, but it changes the color permanently, I want it to be changed just for a half second – Sartheris Stormhammer Feb 19 '14 at 10:44
  • To do it for a short interval of time , probably you have to use thread. – Aparupa Ghoshal Feb 19 '14 at 11:07
  • Also , if you remove the setSelector line from the code , an orangish color is automatically taken , which stays for a very short time - as per your requirement . I would request you to kindly check once removing the setSelector line from you code snippet . – Aparupa Ghoshal Feb 19 '14 at 11:10
0

Here's the problem, turns out the item row when clicked don't get highlighted for a moment because in the item_row.xml I have set a background, without a background it works fine, without any additional code

Sartheris Stormhammer
  • 2,534
  • 8
  • 37
  • 81