简体   繁体   中英

How to enable/ disable ListView onItemClickListener on specific items?

I am designing a game in which the player has to complete the levels in sequence in order to proceed to the next level. Is there a way to implement this?

I have tried this in my custom ListAdapter

@Override
public boolean isEnabled(int position) {
   if(position==0){ return true;}
   else{return  false;}

}

But I'm not able to find a way to work this for more than one level.

You can do it by following code inside setOnItemClicklistener()

ListView listview = (ListView) findViewById(R.id.listview);

listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                if (listview.getChildAt(position).isEnabled()) {
                    listview.getChildAt(position).setEnabled(false);
                }
            }
        }); 

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