我有一個應用程序,用戶在edittext中輸入數據並按下保存按鈕。在一天中(同一天 - >許多用戶數據)保存用戶數據
通過按'保存'我在文件中保存用戶數據(在一列中)和當前日期(在另一列中)。
然後,我按另一個按鈕並繪製(使用achartengine)日期(x軸)數據(y軸)。 「1」(用戶數據) - > 20/4/2013,「2」 - > 20/4/2013,「3」 - > 20,因此,在一天中輸入數據/ 4/2013
並在繪圖中我有3個點在Y軸(OK)和3個點在X軸(不好)。
我想在x軸上有一個點,因爲在同一天輸入的數據。
我保存數據:
public void savefunc(){
SimpleDateFormat thedate = new SimpleDateFormat("dd/MM/yyyy");
Date d=new Date();
String formattedDate=thedate.format(d);
Log.d("tag","format"+formattedDate);
dates_Strings.add(formattedDate);
double thedata=Double.parseDouble(value.getText().toString().trim());
mydata.add(thedata);
File sdCard = Environment.getExternalStorageDirectory();
File directory = new File (sdCard, "MyFiles");
directory.mkdirs();
File file = new File(directory, filename);
FileOutputStream fos;
//saving them
try {
fos = new FileOutputStream(file);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));
for (int i=0;i<mydata.size();i++){
bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
}
...
我如何保存在一天中的用戶數據?
也許一些檢查在這裏:Date d=new Date();
?檢查它是否是同一天。
或者在這裏:bw.write(mydata.get(i)+","+dates_Strings.get(i)+"\n");
但我想不通。
例如,在日期「20/4/2013」中輸入數據「1」,「2」,「3」。
這是我得到現在用我的代碼: This is what I get now http://i35.tinypic.com/2rmsck5.png
但我需要圖如下圖所示:在同一天輸入的數據應該被放在一起:: This is what I want http://i38.tinypic.com/255p5i9.png
------- --------更新----------------------------------------- ---------
mRenderer.setXLabels(0);
for (int i=0;i<mydata.size();i++){
mRenderer.addXTextLabel(i,dates_Strings.get(i));
Date lastDate=null;
String lastdate="";
try{
// the initial date
Date initialDate=formatter.parse(dates_Strings.get(mydata.size()-1));
Calendar c = Calendar.getInstance();
c.setTime(initialDate);
c.add(Calendar.DATE, 1); // increase date by one
lastDate =c.getTime();
}catch ...
}
mRenderer.setXAxisMax(lastDate.getTime());
mRenderer.addXTextLabel(i,dates_Strings.get(i));
}
包括快照太,使其更清楚 – Kiran 2013-04-20 19:17:06