views:

400

answers:

1

I have been using some nice tutorials on drawing graphics on my android. I wanted to also add in the cool gesture demo found here:

http://developer.android.com/resources/articles/gestures.html

That takes these lines of code:

GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this); 

This is fine and dandy yet I realize in my demo i'm trying to build using code from "Playing with Graphics in Android". The demos make sense, everything makes sense but I found out by using:

setContentView(new Panel(this));

as is required by the Playing With Graphics tutorials, then the findViewById seems to no longer be valid and returns null. At first I was about to post a stupider question as to why this is happening, a quick test of playing with the setContentView made me realize the cause of findViewById returning null, I just do not know how to remedy this issue. Whats the key I am missing here? I realize that the new Panel is doinking some reference up but I am not sure how to make the connection here.

The: R.id.gestures is defined right int he main.xml as: (just like the tutorial)

<android.gesture.GestureOverlayView
    android:id="@+id/gestures"
    android:layout_width="fill_parent" 
    android:layout_height="0dip"
    android:layout_weight="1.0" />

So I did confirm the

setContentView(new Panel(this))

is causing the issue. So I know the issue is that I have to figure out how to add the android.gesture.GestureOverlayView to the panel class somehow, I am just not sure how to go about this.

After fighting with this I generally know what I need to do just now how to do it. I think I need either the equivalent of creating a panel in that main.xml OR figuring out how to build whats in main.xml for the gestures in code. I am close because I did this: GestureOverlayView gestures = new GestureOverlayView(this);

which gets me a non null gestures now, unfortunately since I am not telling it to fill Parent anywhere I don't think its really showing up, so I am trying hard to figure out layout pa rams. Am I even on the right track?

A: 

I've been working through some of the sample code myself, and have yet to actually write anything meaningful, but perhaps it's as simple as, the system can't find the view because you've set a different one?

Most of the samples have in the setContentView a reference to the resource (e.g. setContentView(R.id.gestures)), don't they? Therefore it's unsurprising that that view can't later be found. ...unless I'm totally newb failing on this point...

dash-tom-bang
hmmm not sure my comment ever got posted earlier. But yes I suspect that in my example for instance its saying setContentView(new Panel()); So yes I set a different one, but why can't the system find the view, or how do I tell it to find the view? There has to be another way, the one thing about android that gets me is all the usage of the .xml files. But I am learning...
Codejoy