I have an activity where I take the input from edit text and store it in an list.
I also store in list the current date.
Then , I press the save button which
The code that deal with your file must be something like this (not compiled):
public void savefunc(){
List<String> myDate = new ArrayList<String>(); //To store the formatted dates
SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");
Date d=new Date(); //the current date
String sd = thedate.format(d); // sd contains "16/04/2013", the formatted date
myDate.add(sd);
double thedata=Double.parseDouble(value.getText().toString().trim());
mydata.add(thedata);
...
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
for (int i=0;i<mydate.size();i++){
bw.write(mydate.get(i)+","+mydata.get(i)+"\n");
}
}
public void readfunc(){
SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");
Date d;
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
do {
s = br.readLine();
if (s != null ){
String[] splitLine = s.split(","); //first substring is the formatted date
date.add(thedate.parse(splitLine[0])); //do something with exception
data.add(Double.parseDouble(splitLine[1]));
...
Hope it helps.
for dynamic plots use GraphicalView rather then intent::
public GraphicalView mChartView;
creat a xml::
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/graph"
android:layout_width="fill_parent"
android:layout_height="145dip" >
</LinearLayout>
</RelativeLayout>
then in ur code :
LinearLayout layout = (LinearLayout) findViewById(R.id.graph);
mChartView = ChartFactory.mChartView = ChartFactory.getLineChartView(getBaseContext(), dataset, renderer)
layout.addView(mChartView);
After entering values you read from edit text fields right:
then you are passing the new values to add in respective arraylists
then you should call the code for linegraph again after adding new values and remember to clear series before reading arraylists (ie. dataset.clear();
) ie. when line code function starts at beginning add dataset.clear(); because if u dont clear data will overlap and may through exception or line may look thick at old data ...
then call mChartView.repaint();
to refresh graph
these links too ll help u link1 link2