0

我有以下活动

public class BmiHistory extends Activity {


public Cursor cursor;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.bmihistory);
    final DatabaseHandler databaseOpen = new DatabaseHandler(this);
    final SQLiteDatabase db = databaseOpen.getReadableDatabase();

    Cursor c1 = db.rawQuery("select * from bmi", null);
    startManagingCursor(c1);
    c1.moveToFirst();
    this.cursor = c1; 
    while(!c1.isAfterLast()) {
        System.out.println(c1.getString(2));
        c1.moveToNext();
    }
    c1.close();


    BmiGraph drawView = new BmiGraph(this);
    drawView.setBackgroundColor(Color.WHITE);
    setContentView(drawView);

}


}

我从这个活动中调用了以下课程

public class BmiGraph extends View {

Paint paint = new Paint();


public BmiGraph(BmiHistory context) {
    super(context);
    // TODO Auto-generated constructor stub
    System.out.println(context.toString());
}

public void onDraw(Canvas canvas) {
    paint.setColor(Color.BLACK);
    paint.setStrokeWidth(3);
    ...
}


}

我的问题是如何将 Activity 中光标的数据提供给第二类以绘制图表?

非常感谢

4

1 回答 1

0

您可以修改 BmiGraph 类的构造函数以接受您的光标作为输入(见下文)。然后,您将可以从 BmiGraph 类中访问您的光标。

public class BmiGraph extends View {

Paint paint = new Paint();

Cursor _someCursor;    

public BmiGraph(BmiHistory context, Cursor someCursor) {
    super(context);
    // TODO Auto-generated constructor stub
    System.out.println(context.toString());

    _someCursor = someCursor
}

public void onDraw(Canvas canvas) {
    paint.setColor(Color.BLACK);
    paint.setStrokeWidth(3);
    ...
}


}
于 2013-01-03T03:28:27.543 回答