How can I "set View" in right place where I remove an item in ListView (Android) - android

I choose an item to remove from my ListView. And after the Item was removed, my ListView was scrolled back and display at the first Item.
I want my ListView display in right place where the Item I had removed (It like remove a contact in Android Contact list). How can I do that?

I suppose you want to update your ListView display, after you remove an item, right?
When you remove the item, you have to modify your data adapter, and let the ListView change accordingly (something like the MVC pattern behavior). I've seen somewhat similar questions (and the corresponding answers :) ) here and here.
Edit:
Aha, in that case, try using setSelection(int), after recalculating new indices and new item count.

Related

ListView updating Items without being recreated

I want my ListView to work something like the following:
When I press a button (probably from context-menu), I want the user to be able to select more then one item from ListView (probably using check-boxes), but those check-boxes should not be visible before that.
So, the point is, after the user presses a button (let's say "Delete more items"), the listview, should update itself, and appear on every row of the list, a checkbox should appear (allowing me to select the items ID to pass those to server).
How can I achieve that, without having to recreate the list from zero? (how to setVisibility ON, keeping the other content of the ListView as it is, and not doing another request to server).
PS. If you guys, have another better idea, on achieving the Delete More Items, would be much appreciated!
This is just an idea, haven't tried it myself: you build in a checkbox in your listitem layout. Normally, in the getView of your adapter, you set it invisible with
checkBox.setVisibility(8);
When you want to show them, you set some boolean
showBoxes
of your adapter to true, then in the getView oyu don't hide the checkboxes.
Then
notifyDataSetChanged
on the adapter.
Hope it's clear what I mean.

Extended list view: Show text input inside once clicked

I am working on a UI where I have a list view. Each row has 2 information. One is Product name and the other is product ID stacked one over other. So each row has 2 lines of data.
What i want to do with this:
Once a user clicks on each row, it will further expand and show one input and one spinner. So it is basically for putting in Quantity and unit of measure.
Please let me know if this is achievable and if I can refer to some example.
What I need is more like
Taskos To Do List | Task List
https://play.google.com/store/apps/details?id=com.taskos&hl=en
All i need is that the category will not be expandable. Only the items will be expandable. All i need is an example of such app and then I can take it forward.
I think it could be done... you would need to put the extra widgets in your row layout, populate them and hide them upon list creation, then in your onListItemCLick you could unhide them.
Note I have no idea if this would work, but it seems reasonable that it might and it's what I would try and do to achieve the goal.
listView cannot be expanded. however you can use an expandablelistView
But the kind of functionality you want cannot be done this way(I guess.).
You can use
registerForContextMenu("your list View");
to register your list view
onCreateContextMenu
for the kind of action you want to be performed in your case its dialog with EditText and Spinner to have input from user

Adding a row to a ListView that displays "Loading" while information is downloaded. Like in the Market

I've tried, but have had no luck trying to find this answer elsewhere.
I want to add a row to the bottom of my listview that displays "Loading..." and maybe a spinning progress indicator.
My program already loads additional information into the listview once the user scrolls to the bottom. But I want the user to be able to see that the program is indeed loading something.
Example: If you go to the android marketplace and scroll to the bottom of one of the lists, the last row will say "Loading...". Then once the data is loaded, that bar is replaced with the first item of the new data.
Sorry, it's a little hard to describe. I am NOT trying to add a footer to the bottom of the list view. I want it to be an actual item in the listview.
Take a look at the following library:
https://github.com/commonsguy/cwac-endless
It does exactly what you're looking for and it's also very easy to use.
I've used it myself on one of my apps: WorldSpeak. Take a look on it to see the result.
Assuming you have a TextView in the list items, you could add a new item to the end of the list that says "Loading..." and then remove that item when you update the list. I.e., if "hashlist" contains the data as declared in the adapter,
ArrayList<HashMap<String,String>> hashlist ;
HashMap<String,String> loadingitem ;
loadingitem.put( "line1",getString(R.string.loading));
hashlist.add(loadingitem) ;
and then...
// remove "loading..." list item if it's there
hashlist.remove(loadingitem) ;
// then add the new items

How to display "More" list item in ListView?

I want to display a list item that says "More" at the end of my ListView. Clicking on this list-item will perform some action. How can I create this "more" list item?
I don't know about the "Clicking on this list-item will perform some action" part. The typical pattern is that once the user scrolls to the bottom, new material is loaded automatically. Some people do that by detecting the scroll. I do it by putting in a "More" placeholder and detecting when that is used. Here is a component that implements this pattern.
Just add another value to your arrayadapter (or any other adapter), you might be using.set the text to 'more' .
Suppose you have n items in the list then handle the (n+1)th postion click and do your stuff.
You can add a footer to your listview...
Did you check this post out?
Android ListView Footer View not being placed on the bottom of the screen

How do I animate ListView item hights?

I have a simple ListView in my application. What I want to do on a row select is to expand it and show additional details in there and then if some other is selected then collapse the previous one and expand the new one.
I can modify the contents list item row in onListItemClick() method. However how do I animate the change in height of the list item row.
Is there a better way to do it? Or is there a better component still? I don't want to use the expandable list as it's not a group of child lists, instead just expanding the contents with more details.
Any help is much appreciated.
Cheers
Have a look at Lazylist below this.
http://open-pim.com/tmp/LazyList.zip
i think this example is great for build your custom ListView

Categories

Resources