2

This is my XML with 2 LinearLayouts.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent">
    <LinearLayout
            android:id="@+id/ll_one"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
    <LinearLayout
            android:id="@+id/ll_two"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            />
</LinearLayout>

I have downloaded GraphView from http://android.arnodenhond.com/components/graphview. This class extends View. I basically want to initialize 2 graphs via

String[] verlabels = new String[]{"aim", "25%", "50%", "75%", "start"};
String[] horlabels = new String[]{"this", "max"};

float[] values = new float[]{2.0f, 6.0f};
aaaGraphView graphView = new aaaGraphView(this, values, "Graph One",
        horlabels, verlabels, aaaGraphView.BAR);

float[] values2 = new float[]{1.0f, 12.0f};
aaaGraphView graphView2 = new aaaGraphView(this, values2, "Graph Two",
        horlabels, verlabels, aaaGraphView.BAR);

and then to inflate graphView into ll_one, and graphView2 into ll_two.

How should I do this? I have initialized the LinearLayout

   llOne = (LinearLayout) findViewById(R.id.ll_one);

but it does not have inflate() method.

sandalone
  • 41,141
  • 63
  • 222
  • 338

3 Answers3

5

You do not need to inflate another view inside your LinearLayout you'll just have to add another child inside that LinearLayout. Just use the addView() method on the LinearLayout that fits you the best. Here is an example :

   llOne.addView(graphView);
Ovidiu Latcu
  • 71,607
  • 15
  • 76
  • 84
3

If the name of your class which extends View is aaaGraphView try this:

<package1.package2....aaaGraphView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">

</package1.package2....aaaGraphView>
Bob
  • 22,810
  • 38
  • 143
  • 225
3

try this way i have added the linearlayout into another linear layout this way,

setContentView(R.layout.main);
final ViewGroup vg = (ViewGroup) findViewById(R.id.ll_one);
vg.addView(graphView);
MKJParekh
  • 34,073
  • 11
  • 87
  • 98
  • Thanks but it's much simpler to do it via addView() method. – sandalone Oct 18 '11 at 07:32
  • simpler method means what i dont get it? you wanna make it complex? – MKJParekh Oct 18 '11 at 08:39
  • I already initialized ll_one as LinearLayout and you introduced another step `final ViewGroup vg = (ViewGroup) findViewById(R.id.ll_one);`. Your answer is good as well and that's why I up voted it. – sandalone Oct 18 '11 at 09:02
  • i really dont mind anything when i am at learning..this is just to share that in my current project i have made one headerfooter.xml and adding each activity layout in the middle linear layout like this : "ViewGroup vg = (ViewGroup) findViewById(R.id.lldata); ViewGroup.inflate(ShowListAlbumVideos.this, R.layout.newlayout, vg);" so i suggested the same to you..if you find any other then i can also use that. – MKJParekh Oct 18 '11 at 09:09