i have WebView in activity WebViewActivity, and some imagebuttons in main_activity. Can u help me? I need when i click imagebutton1, it will open WebViewActivity ane open in WebView etc google.com. When i Click imagebutton2, it will open etc yahoo.com . Im new in programming, and im not anglophone (my english is bad because im from czech rep). Thanks for any help!

MAIN ACTIVITY

package com.tona.arcig;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.Toast;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        addListenerOnButton();

    }

    public void addListenerOnButton() {

        ImageButton imgbutton1 = (ImageButton) findViewById(R.id.imageButton1);
        imgbutton1.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                Toast.makeText(getApplicationContext(), "I like trains", Toast.LENGTH_LONG).show();
            }
        });
    }

}

WEBVIEWACTIVITY

package com.tona.arcig;

import android.app.Activity;
import android.os.Bundle;

public class WebviewActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_webview);

    }

}

ACTIVITY MAIN XML

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal" >

        <ImageButton
            android:id="@+id/imageButton1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/suplovani"
            android:src="@drawable/suplovani" />

        <ImageButton
            android:id="@+id/imageButton2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/rozvrh"
            android:src="@drawable/rozvrh" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/imageButton3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/prihlasovani"
            android:src="@drawable/prihlasovani" />

        <ImageButton
            android:id="@+id/imageButton4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/email"
            android:src="@drawable/email" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <ImageButton
            android:id="@+id/imageButton5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/email"
            android:src="@drawable/moodle" />

        <ImageButton
            android:id="@+id/imageButton6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="2"
            android:contentDescription="@string/kdm"
            android:src="@drawable/jidelna" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/imageButton7"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:contentDescription="@string/o_aplikaci"
            android:src="@drawable/about" />

    </LinearLayout>

</LinearLayout>

ACTIVITY WEBVIEW XML

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

    <WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</LinearLayout>

MANIFEST

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

    <WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

</LinearLayout>

STRINGS

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="suplovani">Suplování</string>
    <string name="rozvrh">Rozvrh hodin</string>
    <string name="prihlasovani">Přihlašování do systému</string>
    <string name="email">Email</string>
    <string name="moodle">Moodle</string>
    <string name="kdm">KDM</string>
    <string name="o_aplikaci">O Aplikaci</string>
    <string name="app_name">Arcig.CZ</string>
    <string name="title_webview">Arcig.CZ</string>

</resources>

Thank you.

Related posts

Recent Viewed