press button PerformClick

Put your problem here if it does not fit any of the other categories.

press button PerformClick

Postby franckdroid » Sun Mar 11, 2012 11:23 am

Hello ,

i ve currently a problem so maybe you could resolve my problem.:)

i want to press a button programmatically . imagine 2 buttons ,A and B .when you press A , it press the button B programmatically .

for testing I implemented both by Onclick and i used PerformClick , and it work Fine.

But for some reason in my code i have to implement them By OnTouch.

Is there something similar at PerformClick but For Ontouch ?

Thank you
franckdroid
Freshman
Freshman
 
Posts: 3
Joined: Sun Mar 11, 2012 11:13 am

Top

Re: press button PerformClick

Postby Phyll » Tue Mar 13, 2012 9:37 pm

Hi franckdroid,

Is there any reason you cannot simply perform the same operations that are performed by ontouch but without the ontouch trigger?

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: press button PerformClick

Postby franckdroid » Thu Mar 15, 2012 7:46 pm

Hello

Thanks you for your answer phyll.

Yes ..
in fact the message before was an example with 2 buttons.

in fact i ve a button and a webiew. (it's the same way i think)
The button and the Webview are both implemented by Ontouch.
why?
Cause a webview can only be "touch/trigger"with Ontouch. Onclick doesn't works.

so , i d like with the button trigger the webview. it ll open an internet page...

i don't find the way to do it.. if it may exist an performClick but for ontouch...
franckdroid
Freshman
Freshman
 
Posts: 3
Joined: Sun Mar 11, 2012 11:13 am

Re: press button PerformClick

Postby Phyll » Fri Mar 16, 2012 2:43 pm

Hi franckdroid,

Just getting back to this. I mean't can't you do this:

Code: Select all
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.main);

        WebView mWebView = (WebView)findViewById(R.id.mwebview);
        mWebView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View arg0, MotionEvent arg1) {
                mWebView.loadUrl("http://betterpaving.com/");        
                return true;
                }//ontouch
            });//ontouchlistener

        Button button = (Button)findViewById(R.id.bandp);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                mWebView.loadUrl("http://betterpaving.com/");
                }
            });
       
        }//oncreate


Both a touch on the webview and a click on the button load the url. The perform click method is just a convenience method to avoid writing some additional code. So can't you just call the desired action from either input source?

Hope this helps.

Phyll
Phyll
Master Developer
Master Developer
 
Posts: 648
Joined: Fri Oct 14, 2011 11:19 am

Re: press button PerformClick

Postby franckdroid » Wed Jul 11, 2012 12:56 pm

Hello Phyll,

Long time i 'm not come here so i'm sry to could answer only now:)
Thank you a lot for your answer, i tried your code and it could work in this way ,

<ith your code when you click on the button , it load and change the picture link in the webview.
it don't open the url

it's strange there isn't a performclick but for Ontouch..
franckdroid
Freshman
Freshman
 
Posts: 3
Joined: Sun Mar 11, 2012 11:13 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 16 guests