android - how do I add individual strings to a row in CSV file? -
i need csv, started learning how use yesterday, , can't find solution problem. have csv file array: "name, address, id", using opencsv. want able add corresponded strings in row below it. example, if user press button, name "david" added the csv file, , like:
"name,address,id"
"david"
and when user press other button, adress "3 street" added, like:
"name,address,id"
"david, 3 street"
and on, in end there list of names , address , id. can't figured out how , cant similar. maybe there way it?
let me try understand mean,
in scenario 1, should have name added, in scenario 2, should have name,address added,if understand?
this simple , quite achievable. firstly assuming have created row part in csv , saved sd-card
in next part should using arraylist write csv, check out code below
string csv = "c:\\work\\output.csv"; csvwriter writer = new csvwriter(new filewriter(csv)); list<string[]> data = new arraylist<string[]>(); data.add(new string[] {"india", "new delhi"}); data.add(new string[] {"united states", "washington d.c"}); data.add(new string[] {"germany", "berlin"}); writer.writeall(data); writer.close();
take arraylist when scenario 2.
also create separate arraylist contain single column data , populate in same way scenario 1.
you need proper null-checks in scenario 1, else throw nullpointer exception.
most final approach create 2 separate methods
method1- writing single column data csv.(where should handle nullchecks)
method2-the sample code provided more reference http://www.codeproject.com/questions/491823/read-fwritepluscsvplusinplusplusandroid
hope works.
Comments
Post a Comment