2017-04-06 11 views
0

現在の私の活動では、ユーザが指で画面上に描画することによって作成したPathオブジェクトを持っています。おそらくIntentを介して、このPathオブジェクトを次のアクティビティに渡したいと思います。 「「おおよそ(ダブル)メソッドを解決することはできません。そうPathオブジェクトを新しいアクティビティに渡す方法(Android)

float[] pArray = path.approximate(0.5); 
myIntent.putExtra("arr",pArray); 

のような点の配列が、しかし、Androidは私にエラーを与えるとして、私はパスを近似する近似値()メソッドを使用してみましたが

Intent myIntent = new Intent(activity, TrainingActivity.class); 
myIntent.putExtra("image",byteArray); 

/* Pass the Path to the Intent here*/ 

// Start new activity with this new intent 
activity.startActivity(myIntent); 

''、そして何らかの理由で私はそれが動作するようにすることはできませんので、この方法はないと思われる。

+0

はい、 'android.graphics.Path'にはこのようなpublic/visibleメソッドはありません。' @ hide'アノテーションによって隠されています – pskink

+0

docs(https://developer.android.com/reference/android/graphics/)によると、 Path.html#approximate(float))、このメソッドはAndroid Oプレビューでのみ使用できます。 – MatusMak

答えて

0

将来誰かがこの同じ質問をした場合、私が思いついた解決策は、誰かが画面に触れるたびにxとyの座標を記録することでした。私は単に意図にエキストラとして二つの配列を追加し、新にその意図を渡し、次の活動へのパスを構成するこれらの点を渡すために

その後
ArrayList<Float> xCoords = new ArrayList<Float>(); 
ArrayList<Float> yCoords = new ArrayList<Float>(); 

@Override 
    public boolean onTouchEvent(MotionEvent event) { 
     // Get the coordinates of the touch event 
     float eventX = event.getX(); 
     float eventY = event.getY(); 

     switch (event.getAction()) { 
      // When a finger touches down on the screen 
      case MotionEvent.ACTION_DOWN: 
       // Add the coordinates to array lists 
       xCoords.add(eventX); 
       yCoords.add(eventY); 
       // Set a new starting point 
       path.moveTo(eventX, eventY); 
       return true; 
      // When a finger moves around on the screen 
      case MotionEvent.ACTION_MOVE: 
       xCoords.add(eventX); 
       yCoords.add(eventY); 
       // Connect the points 
       path.lineTo(eventX, eventY); 
       break; 
      ... 
      ... 
      ... 

:私はこのようなArrayListのにこれらの座標を置きますアクティビティ

Intent myIntent = new Intent(activity, TrainingActivity.class); 
           myIntent.putExtra("image",byteArray); 

// Add the two arrays with points 
myIntent.putExtra("Xpoints",xCoords); 
myIntent.putExtra("Ypoints",yCoords); 

// Start new activity with this new intent 
activity.startActivity(myIntent); 

本当にPathオブジェクトが必要な場合は、これらのポイントを使用して新しいパスを作成するだけです。

関連する問題