마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

canvas관련 질문입니다. canvas 및 위젯 관련 질문

0 추천
package com.example.normaldistribution;

import java.text.DecimalFormat;
import android.app.Activity;
import android.graphics.Canvas;
import android.graphics.Color;
import android.os.Bundle;
import android.view.*;
import android.widget.*;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.os.Bundle;

public class MainActivity extends Activity {
 View mPage1, mPage2, mPage3;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  MyView vw= new MyView(this);
  this.addContentView(vw, new LinearLayout.LayoutParams(480, 800));  

  setContentView(R.layout.activity_main);
  mPage1=findViewById(R.id.page1);
  findViewById(R.id.selection01).setOnClickListener(mClickListener);
  
  Button btn1=(Button)findViewById(R.id.button11);  
  btn1.setOnClickListener(new Button.OnClickListener() {
   public void onClick(View v1) {
    EditText editTest1 = (EditText)findViewById(R.id.editText01);
    String str = editTest1.getText().toString();
    double sol = normal.area(-5, Double.parseDouble(str), 10);
    DecimalFormat df = new DecimalFormat("0.00000");
    sol = Double.parseDouble(df.format(sol));
    str = Double.toString(sol);
    Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
    }
   });
  
 mPage2=findViewById(R.id.page2);
 findViewById(R.id.selection02).setOnClickListener(mClickListener);

 Button btn2=(Button)findViewById(R.id.button21);  
 btn2.setOnClickListener(new Button.OnClickListener() {
  public void onClick(View v2) {
   EditText editText21 = (EditText)findViewById(R.id.editText21);
   EditText editText22 = (EditText)findViewById(R.id.editText22);

   String str1 = editText21.getText().toString();
   String str2 = editText22.getText().toString();
   
   double sol = normal.area(Double.parseDouble(str2), Double.parseDouble(str1), 10);
   
   DecimalFormat df = new DecimalFormat("0.00000");
   sol = Double.parseDouble(df.format(sol));
   String str = Double.toString(sol);
   Toast.makeText(MainActivity.this, str, Toast.LENGTH_SHORT).show();
   }
  });

 mPage3=findViewById(R.id.page3);
 findViewById(R.id.selection03).setOnClickListener(mClickListener);

 Button btn3=(Button)findViewById(R.id.button31);  
 btn3.setOnClickListener(new Button.OnClickListener() {
  public void onClick(View v3) {
   EditText editText3 = (EditText)findViewById(R.id.editText31);

   String str3 = editText3.getText().toString();
   
   double sol3 = normal.area(Double.parseDouble(str3), 5, 10);
   
   DecimalFormat df = new DecimalFormat("0.00000");
   sol3 = Double.parseDouble(df.format(sol3));
   String str4 = Double.toString(sol3);
   Toast.makeText(MainActivity.this, str4, Toast.LENGTH_SHORT).show();
   }
  });
 }
 
protected static class MyView extends View {
   public MyView(Context context) {
    super(context);
 
   }   
   public void onDraw(Canvas canvas){
     Paint pnt = new Paint();
     pnt.setAntiAlias(true);
     pnt.setColor(Color.BLACK);
     pnt.setStrokeWidth(5);
     canvas.drawLine(200, 400 , 300, 100, pnt);
    }
 }

 Button.OnClickListener mClickListener = new Button.OnClickListener() {
  public void onClick(View v) {
   mPage1.setVisibility(View.INVISIBLE);
   mPage2.setVisibility(View.INVISIBLE);
   mPage3.setVisibility(View.INVISIBLE);

   switch (v.getId()) {
   case R.id.selection01:
    mPage1.setVisibility(View.VISIBLE);
    break; 
   case R.id.selection02:
    mPage2.setVisibility(View.VISIBLE);
    break; 
   case R.id.selection03:
    mPage3.setVisibility(View.VISIBLE);
    break;  
    }
  }
 };
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.main, menu);
  return true;
 }

 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
  // Handle action bar item clicks here. The action bar will
  // automatically handle clicks on the Home/Up button, so long
  // as you specify a parent activity in AndroidManifest.xml.
  int id = item.getItemId();
  if (id == R.id.action_settings) {
   return true;
  }
  return super.onOptionsItemSelected(item);
 }
}
 
class normal {
  static double del(double a){
     double aa=(Math.exp(a*a/-2))/Math.sqrt(2*Math.PI);
     return aa;
    }
   static double area(double a, double b, double n){
     double sum = 0;
     double delta = (b-a)/(2*n);
     double p = a;
     do{
      double xx = del(p);
      double yy = del(p+delta);
      double zz = del(p+2*delta);
      sum += delta/3*(xx+4*yy+zz);
      p = p+2*delta;
      a = a+2*delta;
     }while(a<b);
     return sum;
   }
  }

class 를 통해 화면상에 선을 그리려고 하는데 그려지지가 않네요..

어떻게 해야 그릴 수 있을까요??

songbeomgeun (120 포인트) 님이 2014년 10월 10일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...