简体   繁体   中英

Android: ListView make some specific Items unclickable

I have a ListView in which I have five Items. I want the first 3 items unclickable and on touching them, there should be no color change. And the last two Items should be clickable, which brings me to the next two activities. Please help me if someone has any code example or any helpful link to this problem. I have seen this method but don't know how and where to put this in class.

@Override
public boolean isEnabled(int position) {
    return false;
}

You have to override the isEnabled(int position) method in your adapter's class;

            @Override
            public boolean isEnabled(int position) {
                if (positon > 3) {
                     return true;
                }
                return false;
            }

Assuming that you do not have header view, your isEnabled should look like:

@Override
public boolean isEnabled(int position) {
   return position != 0 && position != 1 && position !=2;
}

isEnabled() is a method of the Adapter of the ListView that you have to overwrite. The documentation can be found here.

您需要在areAllItemsEnabled() http://developer.android.com/reference/android/widget/BaseAdapter.html#areAllItemsEnabled%28%29中返回true以使isEnabled()被调用

isEnabled is a method of your adapter. But this solution will make all your list items unclickable. You need to check the position of your clicked item as well.

getView()方法中,您可以检查位置并调整布局...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM