I wanna draw a graph in android and for that I'm using a chart(I import into my app a jar file) to which I pass the valuess need to be shown...
The problem with this chart is that it occupies the full screen in the activity that is set.
public void onCreate(){
LineView lv;
lv=new LineView(this);
}
The values that I put on the chart are readed from DB using a Async thread so somwewhere I do this:
protected void onProgressUpdate(String...values) {
setContentView(lv);
}
over and over again with the whole data.
And here is my problem:
I tried to use an xml file in which I have a blank linear layout and a button(I wanna set a button underneath my chart) and I tried to pass my chart lv as a child to that Linear layout which doesn't occupies my whole screen:
xml file:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="@+id/titlu"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="250px" >
/>
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop"
android:gravity="bottom"
android:id="@+id/stop"
/>
When I tried in onCreate:
thatlinear=(LinearLayout)findViewById(R.id.titlu);
and this :
thatlinear.addView(lv); in my function onProgresssUpdate()
I got an error which told me that my chart,lv,already has a parent and in order to pass it to other parent I have to remove the initial parent.
So...I did this:
ViewGroup v=(ViewGroup)(lv.getParent());
v.removeView(lv);
But guess what it didn't worked this way...I got a FC-java lang null pointer exception at this line:
v.removeView(lv);
And the last this I tried was this:
LinearLayout llay=new LinearLayout(this);
LinearLayout lytContainer = (LinearLayout) View.inflate(
this, R.layout.chart_speed, null);
lytContainer.setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
llay.addView(lv);
chart_speed is the xml I posted above...
And it didn't worked this way too....still FC.
Question:
How do proceed in order to pass my chart as a child to that LInear layout so it won't filll my entire screen...and I could place buttons underneath it???
EDIT:
I've done this:
setContentView(R.layout.chart_speed);
ViewGroup thatlayout=(ViewGroup)findViewById(R.id.titlu);
thatlayout.addView(lv);
chart_speed-is the name of my whole xml titlu is the @+id of my LinearLayout...
And this is what my logcat displays:
java.lang.NullPointerException
at com.kidroid.kichart.view.AxisView.GenerateValue(AxisView.java:112)
at com.kidroid.kichart.view.AxisView.drawAxisXY(AxisView.java:61)
at com.kidroid.kichart.view.LineView.onDraw(LineView.java:19)
at android.view.View.draw(View.java:6535)
at android.view.ViewGroup.drawChild(ViewGroup.java:1531)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
0 at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.ViewGroup.drawChild(ViewGroup.java:1529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1258)
at android.view.View.draw(View.java:6538)
EDIT2:
I've done this in my ProgressUpdate(){
//initializating the component
thatlayoyt.add(lv);
}
And for a few second it displays correct,but after that I get FC:
java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
at android.view.ViewGroup.addViewInner(ViewGroup.java:1861)
at android.view.ViewGroup.addView(ViewGroup.java:1756)
at android.view.ViewGroup.addView(ViewGroup.java:1713)
FINAL VERSION and it works...I don't think is very correct but it works:
ViewGroup thatlayout;
public void onCreate(Bundle savedInstanceState) {
thatlayout=(ViewGroup)findViewById(R.id.titlu);
}
protected void onProgressUpdate(String...values) {
//initalizating
try{
ViewGroup v=(ViewGroup)(lv.getParent());
v.removeView(lv);
}
catch(Exception e)
{
e.printStackTrace();
}
thatlayout.addView(lv);
}