开发者

Collection for multi-thread-like in java Android

开发者 https://www.devze.com 2023-03-20 22:31 出处:网络
my problem is following (Android): I have 3 Activities (A,B,C) and a manager class: -The manager class hosts a Vector with data.

my problem is following (Android): I have 3 Activities (A,B,C) and a manager class:

-The manager class hosts a Vector with data. -The Activity A asks the manager for the current/previous/next element of the vector, and shows it to the user (internally in the manager i use an int for remember the current position, but i need to change it) - The Activity B, shows a minimized view of the vector allowing to edit/delete some of them - The Activity C is the config menu for the app.

I want to remember the last position consulted at A. That way if the user make: A: current =0,next(current=1) next (current=2) , open B delete an element, back to A: I want the user deleted the element 2 I want to display the 1. if deleted 0 for example y want to display {1,2,3...} If the user deleted 2> theres no problem.

whic开发者_Python百科h kind of collection/element for indexing should I use?

THanks in advance


I see a couple of options. The first is that ActivityB can report back to ActivityA when it closes on what, if any, element is deleted. ActivityA can then adjust the index its showing if necessary. ActivityA should call startActivityForResult to start ActivityB.

Another option is that ActivityA can check in onResume the index of the element it was displaying when it invoked ActivityB. If Vector.indexOf() returns -1, then you know the element itself being displayed was removed. If not, you know the current index you should display.

By the way, unless you need the thread safety of Vector, use ArrayList instead. In the stated use case there's no need for thread safety.

0

精彩评论

暂无评论...
验证码 换一张
取 消