• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

ImageView clickable, Webview and php

StephaneM

Lurker
Oct 8, 2021
4
0
Hello World ! :)
I'm new to this forum and
I'm new to Android Studio programming.

I'm not new to programming ...
C and Cobol in 1992.
HTML and CGI C during the EXPLOSION of the Internet
in 1995 (36 Kb/s with a modem WOW).
PHP, Python and Java.
It's a long run really.

I'm new to Java programming btw.

I'm using Java with Android Studio and I reached a Goal.
1.ImageView clickable
2.Webview
3.PHP returning info about my personnal network
local weather and computer cpu usage for a specific ip address

in the webview.

Sure It would be awesome to only use HttpUrlConnection but it gived me
problem and this is why I decide webview was the answer.

in your AndroidManifest.xml, the usual:
<uses-permission android:name="android.permission.INTERNET"/>

in your activity_main.xml, insert the corresponding views.My Java code (MainActivity.java)
references to 3 ImageViews and the WebView.

here's the Java code:

// begin java code
package com.example.webview001;

import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ImageView;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

private WebView webView;


@override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle("Smarch Dashboard v.02");



ImageView mynetwork = (ImageView) findViewById(R.id.mynetwork);
ImageView mycpu = (ImageView) findViewById(R.id.mycpu);
ImageView myweather = (ImageView) findViewById(R.id.myweather);
webView = (WebView) findViewById(R.id.webview1);

webView.setWebViewClient(new WebViewClient());

mynetwork.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view1) {
webView.loadUrl("http://192.168.1.18/backing/monitor/monitor.html");
}
});

mycpu.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view2) {
webView.loadUrl("http://192.168.1.18/backing/monitor/mycpu.html");
}
});

myweather.setOnClickListener(new View.OnClickListener() {
@override
public void onClick(View view3) {
webView.loadUrl("http://192.168.1.18/curltest/weather.php");
}
});
}
}
// end java code

Any suggestions, advises would be appreciated
Thanks and regards
Steph
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones