Note that there are some explanatory texts on larger screens.

plurals
  1. POMultiple instances of a view object within an android activity
    primarykey
    data
    text
    <p>I have two custom view objects that are created within an activity like so.</p> <pre><code>public class Statistics extends Activity { GraphWindow graph1; GraphWindow graph2; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.statistics); graph1 = (GraphWindow) findViewById(R.id.graph1); graph2 = (GraphWindow) findViewById(R.id.graph2); ... } </code></pre> <p>However they seem to be acting as one instance, so a public method to graph1 will also be executed on graph 2. Do I need to initiate each graph view as a new instance somehow? Where would I do this? </p> <p><strong>EDIT</strong></p> <p>Here is the (condensed) GraphWindow Class:</p> <pre><code>public class GraphWindow extends View { //draw data public ArrayList&lt;DataPoint&gt; data = new ArrayList&lt;DataPoint&gt;(); //set height public int graphHeight = 0; public int indexStart = 0; public int indexFinish = 0; public boolean isTouched = false; public boolean isDraggable = false; public GraphWindow(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); } public GraphWindow(Context context, AttributeSet attrs) { super(context, attrs); } public GraphWindow(Context context) { super(context); } public void setGraphHeight(int graphHeight) { this.graphHeight = graphHeight; } public void isDraggable(boolean isDraggable) { this.isDraggable = isDraggable; } public void panBox(MotionEvent event) { rectX = (int)event.getX(); rectW = this.getWidth()/5 + rectX; this.postInvalidate(); } public void clearData() { this.data.clear(); } @Override public void onDraw(Canvas canvas) { super.onDraw(canvas); ... } @Override public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { ... } } </code></pre> <p>In particular the clear data method will operate on both graph1 and graph2.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload