I am trying to define a class like so, so I can have it show up in XML:
public class MyLineChart extends com.github.mikephil.charting.charts.LineChart {
private Context mContext;
public MyLineChart(Context context) {
super(context);
mContext = context;
}
public MyLineChart(Context context, AttributeSet attrs) {
super(context, attrs);
mContext = context;
}
public LineChart(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mContext = context;
}
// ...
}
So when I am defining this object I am doing:
mChart = (MyLineChart) findViewById(R.id.line_chart);
But what if I'd like to send in other arguments through the constructors? For example say the MyLineChart
class had another field:
private int mSomeInt;
and I'd like to be able to set mSomeInt
through the constructor so I am not just setting mContext
to context
but also mSomeInt
to some integer I pass in. I'm using the integer as an example but it could technically be any argument.
Can this be done?