public class CustomInformation extends Activity
{
DBManager dbManager;// = new DBManager(getApplicationContext(), "Custom_2.db", null, 1);
private double bmi;
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_custom);
dbManager = new DBManager(getApplicationContext(), "Custom_2.db", null, 1);
//double bmi = 0.0;
String gender = dbManager.getGender();
Log.d("gender", gender);
if(gender.equals("남자"))
{
bmi = dbManager.getCurrentWeight()/Math.pow(dbManager.getHeight()/100,2);
}
else if(gender.equals("여자"))
{
bmi = dbManager.getCurrentWeight()/Math.pow(dbManager.getHeight()/100,2);
}
this.bmi = Double.parseDouble(String.format("%.2f",bmi));
Log.d("bmi",String.valueOf(bmi));
LinearLayout layout = (LinearLayout)findViewById(R.id.layout);
MyView mv = new MyView(this);
layout.addView(mv);
}
public double getBmi()
{
return this.bmi;
}
}
------------------------------------------------------------------------------------------------
public class MyView extends View
{
Test test;
public MyView(Context context) {
super(context);
}
public MyView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
public MyView(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
CustomInformation cus = new CustomInformation();
Paint paint = new Paint();
paint.setColor(Color.rgb(206, 242, 121));
paint.setTextSize(40);
paint.setAntiAlias(true);
......
int x=0;
int y = 80;
if(cus.getBmi() <= 18.5)
{
x = (int)(220/18.5 * cus.getBmi());
}
else if(cus.getBmi() <= 23)
{
x = (int)(440/23 * cus.getBmi());
}
else if(cus.getBmi() <= 25)
{
x = (int)(660/25 * cus.getBmi());
}
else if(cus.getBmi() <= 30)
{
x = (int)(880/30 * cus.getBmi());
}
else
{
x = (int)(110/35 * cus.getBmi());
}
Path path = new Path();
path.moveTo(x,y);
path.lineTo(x - 30, y + 60);
path.lineTo(x+30,y+60);
path.close();
canvas.drawPath(path,paint8);
canvas.drawRect(x - 15, y + 60, x + 15, y + 100, paint8);
canvas.drawRect(x-80,y+100,x+80,y+170,paint8);
canvas.drawText(String.valueOf(cus.getBmi()), x-55, y+150, paint7);
//path.lineTo(185,290);
//path.lineTo(225,290);
}
}
위의 코드 CustomInformation의 priavate double bmi의 값을 구하고 구해진 값을 getBmi() 메서드를 통해서
MyView에서 사용하고 싶은데 MyView에서 getBmi() 메서드를 불러오면 bmi값이 0으로 들어옵니다.
어디가 잘못된건가요