how to draw a path in android on canvas from stored coordinates in database..
i had tried fingerpaint but when i am fetching the co-ordinates
from the database its drawing a path from a different location and if i had put a single dot to draw it draws a line from last drawing to this dot..
the following is code to read the coordinates from the database….
public Cursor read() {
Cursor cur = db.query("path_new", null, null, null, null, null, null);
StringBuffer sbx_read, sby_read;
cur.moveToFirst();
float x1 = 0, y1 = 0;
int pid_read = 1;
int cur_pid;
float mX1 = 0, mY1 = 0;
do {
sbx_read = new StringBuffer();
sbx_read.append(cur.getString(0));
sby_read = new StringBuffer();
sby_read.append(cur.getString(1));
cur.moveToNext();
Log.d("X", sbx_read.toString());
Log.d("Y", sby_read.toString());
Path mPath1 = new Path();
String[] sbx_read_array = sbx_read.toString().trim().split(",");
String[] sby_read_array = sby_read.toString().trim().split(",");
// mPath.moveTo(x1, y1);
for (int i = 0; i < sbx_read_array.length; i++) {
x1 = Float.parseFloat(sbx_read_array[i].toString());
y1 = Float.parseFloat(sby_read_array[i].toString());
mPath1.moveTo(x1, y1);
// mPath.reset();
// mX1 = x1;
// mY1 = y1;
float dx = Math.abs(x1 - mX1);
float dy = Math.abs(y1 - mY1);
if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) {
mPath.reset();
mPath1.quadTo(mX1, mY1, (x1 + mX1) / 2, (y1 + mY1) / 2);
mX1 = x1;
mY1 = y1;
// Log.d("X1", String.valueOf(x1));
// Log.d("mX1", String.valueOf(mX1));
// Log.d("Y1", String.valueOf(y1));
// Log.d("mY1", String.valueOf(mY1));
mPath1.lineTo(mX1, mY1);
mCanvas.drawPath(mPath1, mPaint);
}
}
} while (cur.moveToNext());
cur.close();
return cur;
}
here i am getting the path from database into stringbuffer & convert it into String array so the different paths can be store in different records..
my table is…
X-cordinatrs TEXT, Y-cordinatrs TEXT, Path_id INTEGER, PAGE_NO INTEGER
here is the answer..
this is the Do..While loop of your code just replace it with your code..
it will work as u want……..