Log in or register to post comments

Android Button no virtuel button

June 21, 2013 - 11:15am #1

Hi,

i try to start to open a website with an button clicklistener:

 

 Button web = (Button) this.findViewById(R.id.buttonss);
    web.setOnClickListener(new OnClickListener(){

        public void onClick(View v) {
             Uri uriUrl = Uri.parse("website.com");
             Intent launchBrowser = new Intent(Intent.ACTION_VIEW, uriUrl);
             startActivity(launchBrowser);
        }
        
    });

 

Did i have to put it in the ImageTargetsRenderer.java or anywhere else.

Tried a lot nothing works

Thanks

Android Button no virtuel button

July 8, 2013 - 2:10am #10

Some changes need to be done in ImageTargetsRenderer (as explained in the article);

however, the Button should be added in the ImageTargets.java; then, from ImageTargetsRenderer you will need some method that calls to another method in ImageTargets.java to show/hide the button

Android Button no virtuel button

July 8, 2013 - 1:56am #9

Ok....

I mean from all of that, every change i make should be declare or initiate in imagetargetrendere. java ?

 

Android Button no virtuel button

July 8, 2013 - 1:32am #8

this code is to show Toast in imagetarget.java , so how about to show Button ?

The article shows an example of how to show a toast message, as this is one of many possible actions that you can do in the UI, so to exaplain the main concept of how to trigger UI changes in response to target detection;

but then how to specifcally show a Button is a simple matter of Android programming...

 

Android Button no virtuel button

July 8, 2013 - 12:54am #7

Dear Al, and other member

I find this thread related to my case,

after trying to implement the related link on : https://developer.vuforia.com/forum/faq/android-how-can-i-update-my-ui-response-tracking-events

i need to show 3 buttons on UI after tracking events,

and try to put this code into imagetarget.java :

public void addListenerOnButton()
imageButton = (ImageButton) findViewById(R.id.button_web);
 
imageButton.setOnClickListener(new OnClickListener() {
 
@Override
public void onClick(View arg0) {
 
Intent myWebLink = new Intent (android.content.Intent.ACTION_VIEW);
myWebLink.setData(Uri.parse("http://google.com"));
startActivity(myWebLink);
 

the problem is :

I. In Imagertargetrendering.java

// A handler object for sending messages to the main activity thread
    public static Handler mainActivityHandler;

    // Called from native to display a message
    public void displayMessage(String text)
    {
        // We use a handler because this thread cannot change the UI
        Message message = new Message();
        message.obj = text;
        mainActivityHandler.sendMessage(message);
    }

 

this code is to show Toast in imagetarget.java , so how about to show Button ?

 

Android Button no virtuel button

June 22, 2013 - 5:44am #6

Great.

Android Button no virtuel button

June 22, 2013 - 4:22am #5

Thank you Alessandro,

my mistake was that i didnt but my method not after the initApplicationAR() method.

Now it works :-)

Android Button no virtuel button

June 22, 2013 - 4:09am #4

Have you tried adding your button programmatically on top of the mUILayout ?

This should work (as I just verified):

//Add button
Button myButton = new Button(this);
myButton.setText("Click me");
 
myButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
 
            // TODO do something
         }
});
 
mUILayout.addView(myButton,
    new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
 
 
You can add that code at the end of the  initApplicationAR() method

Android Button no virtuel button

June 21, 2013 - 12:51pm #3

Hi Alessandro,

i put it now in the ImageTarget.java

 

 mC = (Button) mUILayout
                .findViewById(R.id.buttonss);

        // Sets the Close Button functionality
        mC.setOnClickListener(new OnClickListener()
        {
            public void onClick(View v)
            {
               Uri...
               
        
            }
    
    });

 

App is starting but there is no reaktion on the button when i clicked...

Android Button no virtuel button

June 21, 2013 - 11:32am #2

Hi, make sure that your clickable view (button) is added on top of other views.

In ImageTargets.java, a good place where to add custom widgets is the mUILayout (you can find it in the code).

For more information about handling views, you can also consult the Android developer guide:

http://developer.android.com/reference/android/view/View.html

http://developer.android.com/guide/topics/ui/declaring-layout.html

 

Log in or register to post comments