Log in or register to post comments

Show button according to object

December 28, 2010 - 8:22pm #1

Hi everybody!

I would like to display a button on the screen when a trackable is recognized. I'm working with the ImageTargets sample and followed the instructions given here https://ar.qualcomm.com/forums/showthread.php?t=32. The Toasts work perfectly.

My main.xml file was modified to look like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:orientation="vertical" android:layout_width="fill_parent"

	<Button android:id="@+id/button" android:layout_width="wrap_content"
		android:layout_height="wrap_content" android:text="my text"
		android:onClick="myMethod" />


I have added the method "myMethod" to ImageTargets.java that should be called when the button is clicked. It looks like this:

public void myMethod(View view) {
	     // do the magic

I'm not sure about where I should create the button. Doing that in the handleMessage method from the Toast example doesn't work.

I would appreciate any hints on how to solve this.
Thanks in advance!

Re: Show button according to object

December 31, 2010 - 6:51am #3

Thanks Kim, I chose to use the Dominoes app for my purposes.

Everytime a new trackable is in the camera's focus I call from the Dominoes.cpp the method beneath.

newTrackableInFocus(const char* nameOfTrackable)
	jstring argument = javaEnv->NewStringUTF(nameOfTrackable);

	jmethodID method = javaEnv->GetMethodID(javaClass, "displayNewControls", "(Ljava/lang/String;)V");
    javaEnv->CallVoidMethod(javaObj, method, argument);

The DominoesRenderer then sends a message to the GUIManager which sets the visibility of the buttons accordingly (for test purposes I only discriminate between the stones and the chips trackable).

 /** Called from native to display new controls. */
    public void displayNewControls(String nameOfTrackable)
    	Message message = new Message();
    		message.what = GUIManager.DISPLAY_STONES_CONTROLS;
    		message.what = GUIManager.DISPLAY_CHIPS_CONTROLS;

Thanks for the advice, Kim.

Re: Show button according to object

December 29, 2010 - 6:45am #2

First off, here's a thread that might be helpful:


I would suggest placing your buttons in a separate view, which you overlay on top of the main view. Inflate and add your view using the code in that thread. Then you can find the button using something like this:

Button myButton = (Button) overlayView.findViewById(R.id.mybutton);

And you can show/hide the button using something like this:


The Dominoes sample project that comes with QCAR SDK 0.10.0 has some sample button manipulation code as well. See the GUIManager.java class.

- Kim

Log in or register to post comments