tags:

views:

21

answers:

0

I'm attemping to add a new LinearLayout defined by xml on top of my opengl view.

I have this working by using pure java:

public class VortexView extends GLSurfaceView {
 public boolean onTouchEvent(final MotionEvent event) {
        show_something();
 }

void show_something()
{
  //context is the main activity object that gets passed into this
  LinearLayout ll = new LinearLayout(context);
  b = new Button(context);
  b.setText("hello world 1");
  ll.addView(b);
  ll.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
  context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
}
}

However I want to be able to do this:

LinearLayout ll = (LinearLayout)findViewById(R.layout.main);
context.addContentView(ll, new LayoutParams(LayoutParams.FILL_PARENT,  LayoutParams.FILL_PARENT));

My xml is:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:layout_width="fill_parent" 
          android:layout_height="fill_parent" 
          android:orientation="vertical" >
<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="10dp"
    android:text="kill"
    />
</LinearLayout>

Everytime I do this though the app crashes. Any ideas?