Android中的achartengine图在SQLite数据库将字符串转换为日期/时间或双打 [英] Converting Strings in SQLite database to Date/Time or Doubles in Android for achartengine graph

查看:156
本文介绍了Android中的achartengine图在SQLite数据库将字符串转换为日期/时间或双打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是转换两个字符串:KEY_DATE和KEY_TIME到日期/时间格式图表。我不知道是不是将它们转换成双打可能是一个解决办法。

My problem is converting two strings: KEY_DATE and KEY_TIME into Date/Time formats for a Chart. I don't know whether converting them into doubles could be a solution either.

我有其中有一个表有四个类型的字符串列SQLite数据库。

I have a SQLite database which has a table with four type STRING columns.

public static final String KEY_ROWID = "_id";
public static final String KEY_WORKOUT = "workout_type";
public static final String KEY_DATE = "date";
public static final String KEY_TIME = "workout_time";

此数据已被存储到与下面的SQL数据库。

This data has been stored into the database with the following SQL.

db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" + KEY_ROWID
                + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_WORKOUT
                + " TEXT NOT NULL, " + KEY_DATE + " TEXT NOT NULL, "
                + KEY_TIME + " TEXT NOT NULL);"

有一个在我的应用程序的锻炼秒表。当用户提交有时间:

There is a stopwatch in my workout app. When the user submits there time:

  • 在当前系统日期转换为字符串,并存储在数据库中的KEY_DATE(格式DD-MMM-YY)
  • 小时,分钟和秒
  • 在秒表LONG值转换为字符串,然后连接起来作为KEY_TIME并存储在数据库中(格式:HH:MM:SS)

我想使用 achartengine 以图形方式显示该数据,这启动并在Eclipse中运行。

I would like to display this data in a chart using achartengine, which is up and running in Eclipse.

KEY_DATE将在x轴上与KEY_TIME将在y轴上。

KEY_DATE will be on the x axis and KEY_TIME will be on the y axis.

以下方法检索KEY_DATE和KEY_TIME从数据库中。

The following methods retrieve KEY_DATE and KEY_TIME from the database.

public String getWorkoutDate(){
    String[] columns = new String[] { KEY_ROWID, KEY_WORKOUT, KEY_DATE,
            KEY_TIME };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
            null, null);
    String result = "";

    int iDate = c.getColumnIndex(KEY_DATE);

    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        result = result + c.getString(iDate);
    }

    return result;
}


public String getWorkoutTime(){
    String[] columns = new String[] { KEY_ROWID, KEY_WORKOUT, KEY_DATE,
            KEY_TIME };
    Cursor c = ourDatabase.query(DATABASE_TABLE, columns, null, null, null,
            null, null);
    String result = "";

    int iTime = c.getColumnIndex(KEY_TIME);


    for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
        result = result + c.getString(iTime);
    }

    return result;
}

我已经创建了下面的方法将字符串转换回日期和时间格式。我不确定如何使用它们,或者如果它们是适合的。

I have created the following methods to convert Strings back into Date and Time formats. I am unsure of how to use them or if they are appropriate at all.

public Date stringToDate(String stringDate) throws java.text.ParseException {

    SimpleDateFormat formatter;
    Date date;
    formatter = new SimpleDateFormat("dd-MMM-yy");
    date = (Date) formatter.parse(stringDate);
    System.out.println("stringToDate: Today is " + date);

    return date;
}

public Date stringToTime(String stringTime) throws ParseException{

    SimpleDateFormat formatter;
    Date time;

    formatter = new SimpleDateFormat("hh:mm:ss");
    time =  (Date) formatter.parse(stringTime);
    System.out.println("Time: " + formatter.format(time));

    return time;

}

我需要在编码这些字符串日期和时间的转换提供帮助。我不知道是什么类型的收集将它们存储在

I need help in coding the conversion of these Strings to date time. I don't know what collection type to store them in.

在achartengine样品中,x和y的值存储在ArrayList的

In the achartengine samples, the x and y values are stored in ArrayList

的KEY_TIME值绝不会超过60分钟在y轴上。因此它可以被转换成一个双如。 35分钟30秒将是35.3。

The KEY_TIME value will never exceed 60 minutes on the y axis. So it could be converted into a Double eg. 35minutes 30 seconds will be 35.3.

KEY_DATE将在x轴上无论是DD-MMM或DD-MMM-YY。我不知道我需要使用存储这种数据是什么类型的ArrayList

KEY_DATE will be on the x axis as either dd-mmm or dd-mmm-yy. I don't know what type of ArrayList I need to use for storing this data.

在我为正确的类型存储的数据,我想我知道如何使用DBHelper至code中的数据achartengine。

Once I have the data stored as the right type, I think I know how to code the data in achartengine using DBHelper.

我是一个新手程序员,需要一些帮助,在code。这是最后一个问题,我的code之前,我的第一个应用程序是准备好谷歌播放市场!任何帮助将大大AP preciated。

I'm a novice programmer and need some help with the code. This is the last problem in my code before my very first app is ready for Google Play market! Any help would be greatly appreciated.

推荐答案

您应该看一看的JavaDoc,也许在为他们的官方网页小组讨论和论坛的支持部分:的 http://www.achartengine.org

You should take a look at the javadoc provided, and maybe at the support section for discussion groups and forums on their official page: http://www.achartengine.org.

在javadoc中应该为您提供您需要提供在阵列的TimeChart,或您选择的图表中的对象和可用的方法,如数据类型的信息。

The javadoc should provide you with information on the objects and methods available, such as the datatypes that you need to provide in the arrays for the TimeChart, or your chart of choice.

该讨论小组可以帮助你更快地得到答案,因为该库已限制使用,有可能不是它的很多知识在这里。

The discussion groups might aid you get faster answers, since the library has restricted use and there might not be much knowledge of it here.

另外的时间/日期相关的计算一个很好的库 http://joda-time.sourceforge.net/

Also a nice library for time/date related calculation is http://joda-time.sourceforge.net/

这篇关于Android中的achartengine图在SQLite数据库将字符串转换为日期/时间或双打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆