Android Tutorial Rearrange ListView lines

I have a ListView that I want to allow the user to rearrange the lines in it.

For example, my ListView is showing 6 lines

Apple
Orange
Rabbit
Toad
Umbrella
Zebra

I want the user to be able to do something like move Zebra up a few lines if they want to. If I can figure out the logic for a button, or buttons or something, I'm sure I can change the actual records in my database so they will stay in the proper order.


Does anyone have a good idea on how I might be able to do this?

Thanks
Alan
 

klaus

Expert
Licensed User
Longtime User
Attached you have an example, as Erel does suggest, with a 'ScrollViewList'.

You can:
Select an item, it's value will be displayed in an EditText view.
Add an item at the end.
Insert an intem at the selected position.
Delete the selected item.
Modify the selected item.
Clear the whole list.
MoveUp an item.
MoveDown an item.

Best regards,
 

Attachments

  • ScrollViewList.jpg
    ScrollViewList.jpg
    31.4 KB · Views: 20,622
  • ScrollViewList.zip
    7.1 KB · Views: 3,410

asawyer13

Member
Licensed User
Longtime User
Thanks for the information.

I do have a question for Klaus.

My app is going to have a scrollview of categories, and then when they click on a category, it will switch to another scrollview that has a list of items.
Your technique will work well when I'm looking at the list of items, but can I make it work when the category list is on the screen?
In other works, I need to be able to highlight the row so I can click on the UP button to move the item up, but if I click on the row, it's going to switch to the detail list for that category.

Alan
 

klaus

Expert
Licensed User
Longtime User
My app is going to have a scrollview of categories, and then when they click on a category, it will switch to another scrollview that has a list of items.
You could have these two scrollviews side by side or one on top and the other on bottm on the screen at the same time.

Best regards.
 

philfred

Member
Licensed User
Longtime User
with images?

Attached you have an example, as Erel does suggest, with a 'ScrollViewList'.

You can:
Select an item, it's value will be displayed in an EditText view.
Add an item at the end.
Insert an intem at the selected position.
Delete the selected item.
Modify the selected item.
Clear the whole list.
MoveUp an item.
MoveDown an item.

Best regards,

Hi Klaus,
This is really useful and I like the code its very clear!

I have a question i though you would know the answer to?

I want to add an image into the panels (not always) so
i have modified the code to add a listview in with the twolinesandbitmap settings but when i run the code it crashes out when it trys to fire the getitemview as I am guessing its looking for a label which isnt there?

Can you tell me how i should modify this so it can work for either, or will the code fall apart because of what i am doing?

Regards
Phil
 

klaus

Expert
Licensed User
Longtime User
Without knowing what you have really done, it's impossible to give you any concrete answer.
You should post your project as a zip file (in the IDE menu Files/Export As Zip).
But you should add an ImageView view and not a ListView.
You could have a look at ScrollView Examples where you find a collection of examples using a ScrollView.
You could also have look at Another ScrollView Example.

Best regards.
 

philfred

Member
Licensed User
Longtime User
Without knowing what you have really done, it's impossible to give you any concrete answer.
You should post your project as a zip file (in the IDE menu Files/Export As Zip).
But you should add an ImageView view and not a ListView.
You could have a look at ScrollView Examples where you find a collection of examples using a ScrollView.
You could also have look at Another ScrollView Example.

Best regards.

Hi Klaus,
I looked at both of them to get to where I am now... :BangHead:

I am a delphi/php programmer so should be able to work this out - but I think maybe I am getting too complicated...

Basic Overview....

I want to have a list on screen that I can add items to re-arrange items and save and load the list...

My son is Autistic and he works with schedules to plan his day..

E.g

Breakfast
Get Dressed
School
Home
Laptop
Tea
Bath
Bed

etc...

But Adding pictures against these helps with anything he doenst read well :)

And ultimately i would like to click on them and get the text to speech engine to talk them to him....

I have been struggling and abandoning code....

I looked at your list view on this one and it looked perfect but could not get it to behave if i added a listview and thought about adding an imageview instead but then there is no text label..

Also the listview bitmap wont go higher than a small size of 40 or 50dips?

So I looked at loading multiple layouts in but then could not see how i could change on the fly the imageview that was loaded?

Really confused and fustrated!

Thanks in advance
Regards
Phil
 

AscySoft

Active Member
Licensed User
Longtime User
The ListView currently only allows you to add items at the end.

Hi, just wondering if there would be a ... say 'EditAt' event with ListView control(view)?
My entire solution is based on list-views, sow at this point it is mandatory not to change them.

I could delete/rebuild this lists using hundreds of records from my database, but as you realize, this is not so elegant.

Please Erel, try to understand...:rolleyes:
 
Top