Clear listview on back button pressed in android - android

I don't know how to clear dynamic listview[coming from database].. There is one activity for search displaying list view if I click on back button and search again.. the previous search data will as is it is, and new search data added to that list.. It mean listview not clearing on re-search, the same data is continuously displaying again and again..
I have tried to finish activity on back button pressed, still listview not clearing and same record displays multiple time as many time as I search that record..
Any solution for that..?? ANy help will be appreciate...
Thanks..

Related

android reach next and previous item of listview

I have a listView that filled by custom Adapter and listed some sounds from external storage.
when user click on each item of listView a custom alerDialog pop-up and it has play, next and previous buttons.
The problem is I have no idea how to reach information of next and previous sound in listView to play them in this alertDialog without closing it?(in other words I want to reach information of my listView from another class(alertDialog)) Thanks for help.

android - Is there a way to cache a View?

I have a complex listview. Every item in this listview has three EditTexts and two Checkboxes. Outside the listview is a Button for adding rows to the listview, one for continue and one to go back.
Continue and Back does both call something like:
setContentView(R.layout.stepX);
The problem:
If you press continue and then go back all items from the listview are empty. Is there a easy way to save the input or hold him in ram?
My current workaround is to create a Class for a listitem and if you continue every itemdata is read and saved to an arraylist. If you go back it read the arraylist and rebuild the listitems.

Iterate through custom ListView to save checked checkboxes and spinners

I have Activity A that runs Activity B with a button click.
Activity B has a list view with custom rows:
some rows have a title and checkboxes.
and some rows have a title and a spinner .
each row the user either checks the preferred checkboxes or chooses from a spinner.
so far so good. my problem is , when clicking back to Activity A, how do I save all the choices?
and by save I don't mean just save his checked boxes but also get the values of his choices back to Activity A.
I don't want the choices to be saved even after I restart the app. only when the app is running .
So basically I need to :
1. get the user's choices and save their values (either from a spinner or from the checkbox)
2. save the ticked checkboxes the next time the user clicks to go to activity B
I thought about using onPause in Activity B , where I will get a reference to the listView, go through every row, see if there is a checkbox or a spinner there, and then somehow see what value is checked (if its checkboxes) and what value is selected(if its a spinner).
I don't know if it's the right approach or not, anyway I really need help here.

how to maintain data consistency in listview

I have a app that displays data in a listview using baseadapter. The user is able to click a element in the listview and it takes the user to a page where they can edit the data that is being displayed on that element. When the user clicks back it takes the user to the listview however the changes are not updated. How can i update the listview once the user clicks back.
I think just set your adapter in onResume() method, so each and everytime you should go to on that screen, each and everytime it will refresh your Adapter.

Want to clear the listview item permanently?

I want to clera the listview item from the screen when pressing the clear all button. So I used the function m_adapter.clear(); It's clearing the items from the screen. But when I again coming back to the app after exit, those views again coming back. I need to clear them permanently. Can anybody help me in this problem?
Code snippet is as follows:
case R.id.deleteAll:{
m_adapter.clear();
}
If you really want to remove and clear your listview permanently your adapter.clear() will not work.
The actual meaning of this method is to clear your listview and not the listview items.
What you actually have to do is to remove all the elements from the array which you are using to populate the listview.
So this is the only way which will ensure you that your listview will not be loaded with data even when come back to your activity and getting out of it.
If not you will have to call your clear() each and every time you enter your activity, thus making it to look like as if there is not data present.
You'll need to clear the source of your listview data, then refresh the listview. That way, when you reopen the activity the data will not be redisplayed as it won't exist anymore.
Eg. If the listview is populated from a database, delete the data from the database, then refresh the listview.

Categories

Resources