Android的 - 如何处理时pressing按钮,并采取结果 - 更新 - >按钮不响应 [英] android -- how to deal when pressing buttons and taking results -- updated-->buttons don't responds

查看:140
本文介绍了Android的 - 如何处理时pressing按钮,并采取结果 - 更新 - >按钮不响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在第一个屏幕上有两个按钮,当用户点击其中的一个,那么他将去到另一个屏幕与其他buttons.I我不知道如何来处理这个问题。

I want in the first screen to have two buttons and when the user clicks one of them ,then he will go to another screen with other buttons.I am not sure how to handle this.

我的主类是:

public class Radiation extends Activity implements OnClickListener {
View num_cores;
View num_mass;

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

    //Set up click listeners
    num_cores=(View) findViewById(R.id.select_cores);
    num_cores.setOnClickListener(this);
    num_mass=(View) findViewById(R.id.select_mass);
    num_mass.setOnClickListener(this);
}

//called when a button is clicked
public void onClick(View v) {
    switch (v.getId()){
    case R.id.num_cores:
        Intent i=new Intent(this,number_cores.class);
        startActivity(i);  
        break;
    case R.id.num_mass:
        Intent k=new Intent(this,number_mass.class);
        startActivity(k);  
        break;
}
}

}

当我preSS的num_cores按钮,用户进入到另一个画面,还有一些输入数据在编辑文本字段和计算按钮的计算,然后显示结果。

When i press the num_cores button the user goes to another screen and there inputs some data in an edit text field and a calculate button does the calculation and then the result is shown.

下面是number_cores.class:

Here is the number_cores.class :

public class number_cores extends Activity implements OnClickListener {
EditText num_cores;
View core_calcs;

 /** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {


    super.onCreate(savedInstanceState);
    setContentView(R.layout.numbercores);

    num_cores=(EditText) findViewById(R.id.num_cores);
    core_calcs=(View) findViewById(R.id.core_calcs);
    core_calcs.setOnClickListener(this);

}


    public void onClick(View v) {
        switch (v.getId()){
        case R.id.core_calcs:
            cores_func();
            break;

        }
      }
        public void cores_func(){
         //some calculations here with result "double fcores=.."
           Intent i=new Intent(this,core_calcs.class);
           i.putExtra("value",fcores);
          startActivity(i);  
       }
  }

在core_calcs.java:

the core_calcs.java:

public class core_calcs extends Activity {

    TextView corecalcs;


     /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.core_calcs);

        corecalcs=(TextView) findViewById(R.id.corecalcs);
        double f=getIntent().getExtras().getDouble("value");
        corecalcs.setText(Double.toString(f));

    }

}

同样也适用于其他的按钮。

the same goes for the other button.

我该如何处理呢?我失去了我的按钮!有没有更有效的方法?
(现在,我的应用程序不运行)

How can i handle this?I am lost in my buttons!Is there a more efficient way? (Right now,my application doesn't run)

- 更新---------------

--UPDATED ---------------

我没有定义在我main.xml中的按钮的宽度,这就是为什么程序崩溃。

I hadn't defined the buttons width in my main.xml that's why the program crashed.

现在,它给我的第一个屏幕,我的两个按钮,但是当我点击他们什么也不会发生。

Now, it gives me the first screen with my two buttons but nothing happens when i click them.

推荐答案

我的错误是在

public class Radiation extends Activity implements OnClickListener {
View select_cores;
View select_mass;

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

    //Set up click listeners
    select_cores=(View) findViewById(R.id.select_cores);
    select_cores.setOnClickListener(this);
    select_mass=(View) findViewById(R.id.select_mass);
    select_mass.setOnClickListener(this);
}

在那里我有查看num_cores我改变查看select_cores,现在工作得很好!

where i had "View num_cores" i changed to "View select_cores" and now works fine!

这篇关于Android的 - 如何处理时pressing按钮,并采取结果 - 更新 - >按钮不响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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