I am currently using a StreamReader
to open a .txt
file from the Assets which contains lines of strings into a ListView
How would I make it so that when I tap on a list view item, it deletes the line from the text File?
public class MainActivity : Activity
{
ListView notesList;
String[] notesArray;
Stream stream;
StreamReader streamReader;
String line;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
ActionBar.Hide();
//Notes
notesList = FindViewById<ListView>(Resource.Id.lvNotes);
//File name
stream = Assets.Open("NotesData.txt");
// Declare new List.
List<string> lines = new List<string>();
// Use using StreamReader for disposing.
using (streamReader = new StreamReader(stream))
{
while ((line = streamReader.ReadLine()) != null)
{
lines.Add(line);
}
}
notesArray = lines.ToArray();
//Load ListView Data
ArrayAdapter adapter = new ArrayAdapter(
this, Android.Resource.Layout.SimpleExpandableListItem1, notesArray);
notesList.Adapter = adapter;
notesList.ItemClick += lvNotes_ItemSelected;
}
private void lvNotes_ItemSelected(object sender, AdapterView.ItemClickEventArgs e)
{
//Where I want the Line to be deleted!
string toast = "Clicked: " + notesList.GetItemAtPosition(e.Position);
Toast.MakeText(this, toast, ToastLength.Long).Show();
}
}