Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,979 members, 7,810,715 topics. Date: Saturday, 27 April 2024 at 01:50 PM

Help Android Code - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Help Android Code (2152 Views)

Need Help On Android Code Expect Enter (2) (3) (4)

(1) (Reply) (Go Down)

Help Android Code by solacong: 6:25pm On Feb 09, 2017
Good day Gurus, Am working on an android application, i have a webview containing some buttons, i want to open an activity whenever the buttons are clicked, Please Help
Re: Help Android Code by Dekatron(m): 6:33pm On Feb 09, 2017
Use intents

. Implicit intent


You set an onClick method. In your onClick method, then declare your intent
Re: Help Android Code by adenuga558(m): 7:33pm On Feb 09, 2017
use intent
Re: Help Android Code by solacong: 8:48pm On Feb 09, 2017
the issue is that if it were to be like open another activity from another (MainActivity in this my case ) i know how to use the onclick and intent , but now am opening/calling the activity with a button from a webview, that is where am confused
Re: Help Android Code by Cooldude68(m): 8:51am On Feb 10, 2017
if I get you right, you wanna place the button on the webview and then launch an activity when u click the button?
Re: Help Android Code by jamb20s: 10:13am On Feb 10, 2017
solacong:
the issue is that if it were to be like open another activity from another (MainActivity in this my case ) i know how to use the onclick and intent , but now am opening/calling the activity with a button from a webview, that is where am confused

This code has not been tested tho , give it a try


in your html , create a button with the name of btnSearch with method captureClick like this

<input type="submit" name="btnSearch" id="submit_id" onclick="btnSearch.captureClick();" />


Now in your Fragment or Activity , use the below code



private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
v.loadUrl(url);
v.addJavascriptInterface(new Object()
{
@JavascriptInterface
public void captureClick() throws Exception //method which you call on button click on HTML page
{
Log.d("LOGIN::", "Clicked"wink ;
Toast.makeText(MainActivity.this, "Login clicked", Toast.LENGTH_LONG).show() ;
}
}, "btnSearch"wink ;
// identifies which button you click
return true;
}
}


hope this help
Re: Help Android Code by solacong: 4:13pm On Feb 11, 2017
Cooldude68:
if I get you right, you wanna place the button on the webview and then launch an activity when u click the button?

Yes, i decided to use and accordion which i can't achieve using XML
Re: Help Android Code by solacong: 4:13pm On Feb 11, 2017
jamb20s:


This code has not been tested tho , give it a try


in your html , create a button with the name of btnSearch with method captureClick like this

<input type="submit" name="btnSearch" id="submit_id" onclick="btnSearch.captureClick();" />


Now in your Fragment or Activity , use the below code



private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView v, String url) {
v.loadUrl(url);
v.addJavascriptInterface(new Object()
{
@JavascriptInterface
public void captureClick() throws Exception //method which you call on button click on HTML page
{
Log.d("LOGIN::", "Clicked"wink ;
Toast.makeText(MainActivity.this, "Login clicked", Toast.LENGTH_LONG).show() ;
}
}, "btnSearch"wink ;
// identifies which button you click
return true;
}
}


hope this help


Thanks i will check it out
Re: Help Android Code by solacong: 1:06pm On Feb 15, 2017
jamb20s:



Chairman i tried, i can't get it to right, i don't know if you can help with example
Re: Help Android Code by 0luwatope(m): 4:36pm On Feb 15, 2017
Ask straight forward questions, do you want to place a button on top of a webview? what does the webview does? does it access the internet or ¿f¿ there is an html file in ur res folder? if you wan-t the button to work with the webpage, that means youre going to add the button to the url/website and not the android xml file
Re: Help Android Code by solacong: 6:10am On Feb 16, 2017
0luwatope:
Ask straight forward questions, do you want to place a button on top of a webview? what does the webview does? does it access the internet or ¿f¿ there is an html file in ur res folder? if you wan-t the button to work with the webpage, that means youre going to add the button to the url/website and not the android xml file

This is how it goes

I have buttons inside a webView (local, its not accessing internet) and i want the webView to open some activities. The reason why i used the WebView is that, it contain an accordion, which i don't know how to program using XML/Java, i hope you understand me now ?
Re: Help Android Code by 0luwatope(m): 9:23am On Feb 16, 2017
solacong:


This is how it goes

I have buttons inside a webView (local, its not accessing internet) and i want the webView to open some activities. The reason why i used the WebView is that, it contain an accordion, which i don't know how to program using XML/Java, i hope you understand me now ?
Well, if the button ain't showing on top of the webview, try re-wrsiting your code so that the <button comes before <WebView. Then set an onClicklistner for that button Or make ways to learn how to write that your accordion in xml format. And here is another tip, make use of stackoverflow more often when you need help cuz you will find only few good programmers here
Modified: i think an accordion is a kinda animated listing of items on a website using mostly html, css and javascript. Bro, if the button you want to click will toggle the animation or move you from index.html to about.html still under the same app, you do not need an xml <Button. instead, you just need to add the
Re: Help Android Code by jamb20s: 6:50pm On Feb 16, 2017
solacong:


Chairman i tried, i can't get it to right, i don't know if you can help with example


Watch this video here to see if thats what you are talking bout



https://www.youtube.com/watch?v=lwYmNV4XT_A
Re: Help Android Code by solacong: 4:45am On Feb 17, 2017
jamb20s:


Exactly, that is just it, please help
Re: Help Android Code by jamb20s: 12:20pm On Feb 17, 2017
Re: Help Android Code by solacong: 9:29pm On Feb 17, 2017
Re: Help Android Code by jamb20s: 10:13pm On Feb 17, 2017
solacong:

Bro Thanks, i will apply it
you are welcome
Re: Help Android Code by jamb20s: 6:05pm On Feb 28, 2017
solacong:


Bro Thanks, i will apply it

Sorry , i cant access the email i used to register, but i have change it now , you can resend your mail ...
Thanks
Re: Help Android Code by airsaylongcome: 12:35pm On Aug 24, 2021
solacong:
Good day Gurus, Am working on an android application, i have a webview containing some buttons, i want to open an activity whenever the buttons are clicked, Please Help

U tried messaging me. What's good?
Re: Help Android Code by solacong: 7:03pm On Aug 24, 2021
airsaylongcome:


U tried messaging me. What's good?

i want to find out about stuff and how you can help with some info
Re: Help Android Code by airsaylongcome: 11:29pm On Aug 24, 2021
solacong:


i want to find out about stuff and how you can help with some info

Go on. I'm all ears

(1) (Reply)

Kenyan Launches World’s First GUI Based Software Development Kit / Why Isn't There A Decent 3D Game Of Any Kind From Nigerian Programmers? / Exam Prep - Fun Exam Preparatory App [new]

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 24
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.