Why ListView Items becomes not clickable after scroll

一曲冷凌霜 提交于 2019-12-07 13:11:04

问题


I created a custom ListView with ImageView and TextViews and every thing worked fine until i tried to implement onItemClick, which for the time being only shows a Toast.

The problem occurs when i scroll down my ListView: it won't receive any clicks.

Funny thing is that when i use the keyboard to move from item to item it works and when i hit enter the Toast is shown

This is the code i used for onItemClick listener.

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
    RestaurantReservationBean clickedItem = resultArray.get(position);

    Toast.makeText(this, clickedItem.getName()+", "+clickedItem.getCost(), 1000).show();
}

回答1:


i think i solved this problem: after going through some documentation i figured out that this problem comes from the textviews and imagesview on top of each row which block the onitemselected listener. so i tryed to refresh the list view after scroll and it worked just fine. here's what i did hoping it 'll help those who may come accross this problem

listView.setOnScrollListener(new OnScrollListener() {
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            if ( scrollState == OnScrollListener.SCROLL_STATE_IDLE )
            {
              listView.invalidateViews();
            }

        }

        @Override
        public void onScroll(AbsListView arg0, int arg1, int arg2, int arg3) {}
    });


来源:https://stackoverflow.com/questions/7093483/why-listview-items-becomes-not-clickable-after-scroll

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!