简体   繁体   中英

Edit button in listview item depending on other listview items

I would like to start by saying if you can think of a better title for this problem, feel free to change it since I have no clue how to explain this in a short way.

So here is my problem:

For the application I am trying to make I have these schedules, one schedule for today, and one for upcoming days. Both of these are a listview inside a fragment.

(I used those fragments to create tabs to seperate the two.)

Each game (let's call them games because calling them activities would be confusing) on the schedule has a status, and here is where the annoying part comes. I have been asked to check if any game has been started, and if so I need to disable the buttons to start any other game than the one that is already ongoing.

EDIT: The main problem is that I cannot use findViewById on the listview item because apparently it is a null object reference

I made a little "paint"ing to give you more of a graphical representation.

绘画应该是什么

So long story short, I need a way to check the status inside of every listview item inside of the listview inside of the fragment inside the activity to use said status to disable every button except for the one of the ongoing game.

Little side note: If no games have been started yet, all buttons are enabled.

I hope this made sense.

If you want some code to go with this, feel free to ask but be warned, I am making this inside a testing app so a lot of useless testing data and sloppy code.

EDIT: This is where I am stuck in a more clear example: The start buttons are enabled but should be disabled.

滚动之前

Scrolling further down the list, there is a started 'game' and right below it, a game with the same status as in the previous picture where the button is disabled as it should be.

游戏开始后,它显示应有的状态

This is because the "isStartable" boolean in my code goes to false after the game with status "start" has passed and the following items are disabled.

When I scroll back up, it is how it should be, the items are all disabled but I need them to be like this when the listview gets filled. Any way to refresh the data in this listview and taking the "isStartable" boolean with it?

This is what it looks like after I scroll back up. 向上滚动后

create a model class for your listview data items. Set a boolean variable in model class like isGameStarted. Set that variable as per your result.Then in your listview adapter, put a condition as below

if(isGameStarted){
    holder.startButton.setEnable(true);
else
    holder.startButton.setEnable(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