Reputation: 189
I'm coding an app for android. How can I pass an int array from my activity to my view class? I've searched but not found anything that seems to answer my question. I have this class:
public class ConvertToGrid extends Activity{...}
which takes the user's input from the Main activity's layout (using an intent) and converts it into an int array: int[] binary = {...}
which has 64 values. How do I get it into this:
public class DrawGrid extends View{...}
I naively tried an intent but unless I was doing it wrong, it seemed like the wrong thing to do for a view! Also, as an aside I assume I don't need to declare my View in the Manifest like I do my activities?
Upvotes: 2
Views: 367
Reputation: 14022
Create a constructor that it has usual parameters plus int array,for example:
public class DrawGrid extends View {
private int[] intArray;
public DrawGrid(Context context,int[] intArray) {
super(context);
// TODO Auto-generated constructor stub
this.intArray = intArray;
}
public DrawGrid(Context context, AttributeSet attrs, int defStyle,int[] intArray) {
super(context, attrs, defStyle);
// TODO Auto-generated constructor stub
this.intArray = intArray;
}
public DrawGrid(Context context, AttributeSet attrs,int[] intArray) {
super(context, attrs);
// TODO Auto-generated constructor stub
this.intArray = intArray;
}
}
Upvotes: 0
Reputation: 18151
Just create a constructor that have param int[]
public DrawGrid(int[] binaries)
{
// constructor
}
Upvotes: 0
Reputation: 10083
Try this
public class ConvertToGrid extends Activity{.
Public int[] binary = {...}
public class DrawGrid extends View{...}
..}
Upvotes: 1
Reputation: 3890
public class DrawGrid extends View{
int[] binary;
public void setBinaryData(int[] binary)
{
this.binary = binary
}
}
Upvotes: 0