第三个链接不起作用

时间:2014-07-02 07:04:06

标签: java android xml eclipse

我创建了一个按钮,将我带到另一个页面,在另一个页面中,还有另一个按钮转到另一个页面,因此第1页,第2页和第3页不能与我合作,请在{I形状http://oi62.tinypic.com/2m7g4et.jpg时查看点击“鱼指南”它带我到另一个有另一个按钮“鱼”,当我点击“鱼”它不带我到第3页!

activity_main.xml中

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#1d72c3" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:gravity="center"
        android:orientation="vertical"
        android:textStyle="italic" >

        <Button
            android:id="@+id/fishguide"
            android:layout_width="fill_parent"
            android:layout_height="55dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="Fish guide"
            android:textSize="20sp"
            android:textStyle="italic" />
    </LinearLayout>

</RelativeLayout>

fishguide.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#1d72c3"
    android:textStyle="italic" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:textStyle="italic" >

        <Button
            android:id="@+id/fish"
            android:layout_width="fill_parent"
            android:layout_height="60dp"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="Fish"
            android:textSize="22sp"
            android:textStyle="italic" />
    </LinearLayout>

</RelativeLayout>

fish.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#1d72c3" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:orientation="vertical"
        android:textStyle="italic" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:src="@drawable/bala" />

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:text="Balabanka"
            android:textSize="18sp"
            android:textStyle="italic" />
    </LinearLayout>

</RelativeLayout>

MainActivity.java

package com.d.di;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity extends Activity {

    Button button3;

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

    public void addListenerOnButton() {
        final Context context = this;

        button3 = (Button) findViewById(R.id.fishguide);

        button3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, PageThree.class);

                startActivity(intent);

            }

        });

    }

}

PageThree.java

package com.d.di;

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

public class PageThree extends Activity {

    Button button3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fishguide);
    }
}

我做了第三页,它运行但是它错了

MainActivity2.java

package com.d.di;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.view.View.OnClickListener;

public class MainActivity2 extends Activity {

    Button fishlink;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fishguide);
        addListenerOnButton();
    }

    public void addListenerOnButton() {
        final Context context = this;
        fishlink = (Button) findViewById(R.id.fish);

        fishlink.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, PageFish.class);
                startActivity(intent);

            }

        });

    }

}

PageFish.java

package com.d.di;

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

public class PageFish extends Activity {

    Button fishlink;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fish);
    }
}

帮助:)


当我点击“Fish”时,编辑/它将“Fish guide”改为“Fish”,它再次将我带到“Fish”等等,它不会转到第三页!

PageThree.java

package com.d.di;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class PageThree extends Activity {

    Button button3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fishguide);
        addListenerOnButton();
    }
    public void addListenerOnButton() {
        final Context context = this;

        button3 = (Button) findViewById(R.id.fish);

        button3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(context, PageThree.class);

                startActivity(intent);

            }

        });
}
}

2 个答案:

答案 0 :(得分:0)

您已使用

setContentView(R.layout.fishguide);
PageThree.java中的

将其更改为要在图像中显示第三张图像的xml。比如,third.xml

setContentView(R.layout.third);

你已经完成了。

答案 1 :(得分:0)

注意:您一次又一次地获得相同的布局,因为在PageThree.java中您正在使用意图PageThree.java开始活动。相反,只需将其更改为PageFish.java

因此,当您处于第二个布局(PageThree.java)时,只需在按钮点击时启动第三个布局(PageFish.java)的活动,如下所示 -

<强> PageThree.java

package com.d.di;

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

public class PageThree extends Activity {

    Button button3;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.fishguide);

    button3 = (Button) findViewById(R.id.fish);

        button3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {

                Intent intent = new Intent(PageThree.this, PageFish.class);

                startActivity(intent);

            }

        });

    }
}