I have my app set so that when a user clicks on an item in the listview it disappears. However when I close the activity or app the list refreshes dully with all items included. Is there a way for me to delete the item permanently after the click it?
This is my code:
public class Movies extends AppCompatActivity {
ArrayAdapter<String> arrayAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movies);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final ListView moviesListView = (ListView)findViewById(R.id.moviesListView);
final ArrayList<String> topMovies = new ArrayList<String>(asList("1. The Shawshank Redemption", "2. The Godfather", "3. The Godfather: Part 2",
"4. The Dark Knight", "5. Pulp Fiction","6. Schlinder's List","7. 12 Angry Men","8. The Lord of the Rings: The Return of the King",
"9. The Good, the Bad and the Ugly","10. Fight Club","11. The Lord of the Rings: The Fellowship of the Ring","12. Star Wars: Episode V - The Empire Strikes Back",
"13. Forrest Gump","14. Inception","15. One Flew Over the Cuckoo's Nest","16. The Lord of the Rings: The Two Towers","17. Goodfellas",
"18. The Matrix","19. Seven Samurai","20. Star Wars: Episode IV - A New Hope","21. City of God","22. Se7en","23. The Silence of the Lambs",
"24. The Usual Suspects","25. It's a Wonderful Life","26. Life is Beautiful","27. Leon: The Professional","28. Once Upon a Time in the West",
"29. Spirited Away","30. Interstellar","31. Saving Private Ryan","32. Casablanca","33. American History X","34. Psycho","35. City Lights","36. Raiders of the Lost Ark",
"37. Rear Window","38. The Intouchables","39. Modern Times","40. The Green Mile","41. Terminator 2: Judgement Day","42. The Pianist","43. The Departed",
"44. Whiplash","45. Back to the Future","46. Memento","47. Gladiator","48. Apocolypse Now","49. Dr. Strangelove","50. The Prestige"));
arrayAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, topMovies);
moviesListView.setAdapter(arrayAdapter);
final MediaPlayer mPlayer = MediaPlayer.create(this, R.raw.pindrop);
moviesListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String toRemove = arrayAdapter.getItem(position);
arrayAdapter.remove(toRemove);
}
});
}
}