I have created a listview that allows users to tick off movies on the list that they have seen. The only problem is that when I change activity or close the app it resets all elements in the listview to default. I'm wondering if there's a way to save these changes using my current code.
public class Movies extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_movies);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ListView moviesListView = (ListView)findViewById(R.id.moviesListView);
final ArrayList<String> topMovies = new ArrayList<String>(asList("The Shawshank Redemption", "The Godfather", "The Godfather: Part 2",
"The Dark Knight", "Pulp Fiction","Schlinder's List","12 Angry Men","The Lord of the Rings: The Return of the King",
"The Good, the Bad and the Ugly","Fight Club","The Lord of the Rings: The Fellowship of the Ring","Star Wars: Episode V - The Empire Strikes Back",
"Forrest Gump","Inception","One Flew Over the Cuckoo's Nest","The Lord of the Rings: The Two Towers","Goodfellas",
"The Matrix","Seven Samurai","Star Wars: Episode IV - A New Hope","City of God","Se7en","The Silence of the Lambs",
"The Usual Suspects","It's a Wonderful Life","Life is Beautiful","Leon: The Professional","Once Upon a Time in the West",
"Spirited Away","Interstellar","Saving Private Ryan","Casablanca","American History X","Psycho","City Lights","Raiders of the Lost Ark",
"Rear Window","The Intouchables","Modern Times","The Green Mile","Terminator 2: Judgement Day","The Pianist","The Departed",
"Whiplash","Back to the Future","Memento","Gladiator","Apocolypse Now","Dr. Strangelove","The Prestige"));
ArrayAdapter<String> 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) {
if(view.getAlpha()==1f) {
mPlayer.start();
Toast.makeText(getApplicationContext(), "You Watched " + topMovies.get(position), Toast.LENGTH_LONG).show();
view.animate().alpha(0.2f);
}
else{
view.animate().alpha(1f);
}
}
});
}
}