1

What to do if a ListView stopped blinking on tapping after adding onClickListener and onClick() method for convertView in adapter? I extended ArrayAdapter and everything was okay. Then I added this:

convertView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //some code
        }

onClick() worked properly (unlike setting onClickListener for whole ListView in Activity class, as I tried before, but unsuccessful), but it doesn't blink anymore when I "click". Where's the problem?

Justin McGuire
  • 365
  • 1
  • 5
  • 18
  • Could you specify what you mean by 'blink'? – Mikhail Jul 07 '15 at 13:32
  • @Arkadiy возможно, не совсем точно слово подобрал. Обычно при нажатии на ячейку она становится чуть темнее, а у меня - никакой визуальной реакции, хотя функциональность onClick() выполняется – Justin McGuire Jul 07 '15 at 13:39
  • @Arkadiy or you don't speak Russian? Sorry if I'm mistaken, I saw your name and thought you did. – Justin McGuire Jul 07 '15 at 13:45
  • Я говорю по-русски, просто не уверен, что здесь допустимо на не-английском – Mikhail Jul 07 '15 at 13:50
  • Отвечу на русском пока: можешь попробовать сделать background у лэйаута convertView не просто цветом/изображением, а selector http://stackoverflow.com/questions/4533320/android-clickable-layout – Mikhail Jul 07 '15 at 13:55

1 Answers1

0

You should probably not use convertView.setOnClickListener, instead try using listView.setOnItemClickListener to listen to click on your rows.

I think this the reason of your problem. The reason the row "blink" is because the background is a selector drawable that has a different color for the pressed state. If you intercept the user interaction with your listener the row is never pressed.

sonic
  • 1,894
  • 1
  • 18
  • 22