Android的2.3.3,Eclipse的 - 无法切换到其他页面布局后使用按钮 [英] Android 2.3.3, Eclipse - unable to use button after switching to other layout pages

查看:95
本文介绍了Android的2.3.3,Eclipse的 - 无法切换到其他页面布局后使用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概述:
我在我的节目两页;主页和其他页面。

Overview: I have two pages in my program; the main page and the other page.

在主网页我有两个按钮;一键切换到其他页面,并添加按钮增加了一些价值在一起。

On the main page I have two buttons; one button switches to the other page and the Add button adds some values together.

在其他页面我有一个按钮,这使我回主画面。

On the other page I have a single button that brings me back to the main page.

目前我能没有问题的两个页面之间切换。

Currently I'm able to switch between the two pages without issue.

我的问题:
当我第一次打开程序,我可以单击Add按钮,它会添加值在一起。我可以继续没有问题的两个页面之间切换。
不过,我已转页后,当我点击添加按钮,我的程序崩溃。

My Issue: When I first open the program I can click the Add button and it will add the values together. I can continue to change between the two pages without issue. However, after I have switched pages, when I click the Add button, my program crashes.

这是我的java文件。

Here is my java file.

    package com.test;
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.*;

    public class AswitchActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    Button enterScoreButton = (Button) findViewById(R.id.button1);
    enterScoreButton.setOnClickListener(enterScoreButtonListener);
}

public OnClickListener enterScoreButtonListener = new OnClickListener() 
{
    @Override
    public void onClick(View v1) 
    {
    }

    public int addEntireHole(int addedHoles) {
        return (addedHoles);
    }
};

//This section goes from the main page to the other page
public OnClickListener Startpage = new OnClickListener(){
    public void onClick(View v2){
    }
};

public void onCreate(View view){
    Button buttonSwitchMain = (Button)findViewById(R.id.btnSwitch);
    buttonSwitchMain.setOnClickListener(Startpage);
    setContentView(R.layout.other);
 }

//This section goes from the other page to the main page

public OnClickListener otherpage = new OnClickListener(){
    public void onClick(View v3){
    }
};


public void onCreate3(View view2){
    Button buttontoMain = (Button)findViewById(R.id.btnBack);
    buttontoMain.setOnClickListener(otherpage);
    setContentView(R.layout.main);
 }

}

推荐答案

在你的方法 onCreate3 ,要求在的setContentView 你应该叫

In your method onCreate3, after calling setContentView you should call

enterScoreButton.setOnClickListener(enterScoreButtonListener);

再一次。

这篇关于Android的2.3.3,Eclipse的 - 无法切换到其他页面布局后使用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆