0

I have a chart that I use to display a graph.

To display the chart I use a jar taken from here:

http://writerbay.wordpress.com/2011/03/12/android-tutorial-displaying-chart-on-android/#comment-54

And the code for it is also similar to that one....and it looks like this:

package com.google.android.chartView;

import com.kidroid.kichart.model.Aitem;    
import com.kidroid.kichart.view.LineView;    
import android.app.Activity;    
import android.graphics.Color;
import android.os.Bundle;

public class chartView extends Activity {
  /** Called when the activity is first created. */
  LineView lv;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    String xaxis[]=new String[4];
    xaxis[0]="2006";
    xaxis[1]="2007";
    xaxis[2]="2008";
    xaxis[3]="2009";
    float line1[]=new float[4];
    line1[0]=120;
    line1[1]=240;
    line1[2]=500;
    line1[3]=100;
    float line2[]=new float[4];
    line2[0]=100;
    line2[1]=650;
    line2[2]=700;
    line2[3]=300;
    float line3[]=new float[4];
    line3[0]=50;
    line3[1]=180;
    line3[2]=360;
    line3[3]=900;
    Aitem items[]=new Aitem[3];
    items[0]= new Aitem(Color.BLUE,"pauOut",line1);
    items[1]= new Aitem(Color.GREEN,"pauOut",line2);
    items[2]= new Aitem(Color.YELLOW,"pauOut",line3);
    lv=new LineView(this);
    lv.setTitle("Yearly Budget");
    lv.setAxisValueX(xaxis);
    lv.setItems(items);
    setContentView(lv);
  }
}

The problem I'm facing is that the chart fills entire my image and when I also wanna place a button on that activity it won't get visible because the chart occupies the full screen....

Question: Is someone who could tell me how to place that chart in order for it not to fill my entire screen so I could place button underneath it?? Thx...My app is on android

WarrenFaith
  • 57,492
  • 25
  • 134
  • 150
adrian
  • 4,574
  • 17
  • 68
  • 119

1 Answers1

0

You're calling setContentView on just the layout object you've created. So thats all that will be shown!

Try using an xml file containing a blank linearlayout, and a button setup how you want it, and then in code, ThatLinearLayout.addView(lv);

Eric
  • 1,953
  • 4
  • 24
  • 33
  • and to give up setContentView(lv);? – adrian Jun 02 '11 at 23:03
  • Yep, you'd instead call setContentView(YourXMLLayout); And do it before you attempt to do the addView method. Search around SO or the android Developer docs for simple layout tutorials, thats all this is :) It does look like you already call a main.xml, so maybe just edit your main.xml? – Eric Jun 02 '11 at 23:08
  • I've done that and it works...but after a few moments....I get the following exception: 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) – adrian Jun 02 '11 at 23:15
  • I understand what it says but I don't know who is child's parent:-S – adrian Jun 02 '11 at 23:16
  • 1
    I did this in my onCreate: lv=new LineView(this); (ViewGroup)(lv.getParent()) I wanted to find the initial parent and then call removeView()....but it doesn't has such an option!!!! – adrian Jun 02 '11 at 23:22
  • I did this: ViewGroup v=(ViewGroup)(lv.getParent()); v.removeView(lv); and it work but now I get FC with java Null PointerException at this line: v.removeView(lv); any idea why? – adrian Jun 02 '11 at 23:28
  • What you need to do is assign an id attribute to the layout in your XML, then call something like `LinearLayout myLayout = getViewById(R.id.theLayoutID);` then call `myLayout.addView(lv);` This is all very basic android layout mgmt, you should really check out some of the API demos or the developer.android.com website if this stuff is tripping you up! – Eric Jun 02 '11 at 23:34
  • I did that...and I know it basic...but it's not working. it tells me..in my logcat that my child view already has a parent...and I have to remove that parent first and after that to do: myLayout.addView(lv)!!That I was tryng to tell u....how do I remove the initial parent of the child of the parent !!!???Thx:)...Nice name Eric...are u swedish somehow? – adrian Jun 02 '11 at 23:43
  • You shouldnt have to remove any views. Im posting from my mobile so i cant give you a full code working but check this answer out it has most of the concepts you are working with http://stackoverflow.com/questions/2759290/how-to-programmatically-add-view-in-viewflipper – Eric Jun 02 '11 at 23:48