安卓 Intent 问题

标签 android

我想在单击按钮时在另一个 Activity 中显示计算的详细信息。 如何实现这一目标。 我的第一个 Activity java 代码是

public void onClick(View v)
{
   if(v.getId()==R.id.Button07) 
    {
        Intent intent=new Intent(AdvancedCalculator.this,calculatedData.class);
        startActivity(intent);
    }

我想做的计算是

String a,b;
Integer vis;
a = txtbox3.getText().toString();
b = textview1.getText().toString();
vis = (Integer.parseInt(a)*Integer.parseInt(b))/100;
tv.setText(vis.toString());

我希望在按下提交按钮时在下一个 Activity 中显示结果“电视”。 我需要在哪里包括这个计算。还有什么进一步的步骤

非常感谢任何帮助 谢谢

最佳答案

在您的第一个 Activity 中:

public void onClick(View v) {

    //Put your calculation code here

    Bundle b = new Bundle();
    b.putString("answer", youranswer);
    //You could also use putInteger, whichever you prefer.

    Intent intent=new Intent(AdvancedCalculator.this,calculatedData.class);     
    intent.putExtras(b);
    startActivity(intent);


}

在您的第二个 Activity 中,在 onCreate 中放置以下内容:

Bundle b = getIntent().getExtras();
String answer = b.getString("answer");

答案是你的 key 。它用于标识您想从 bundle 中获得什么。使用唯一键意味着您可以根据需要将多个值传递给下一个 Activity 。

关于安卓 Intent 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5830326/

相关文章:

java - 哪里可以学习JNI函数的用法?

android - 阻止广告出现在 android webview 中

Android ADT Eclipse 布局编辑器给出 StackOverflowErrors

android - 一个一个地运行异步任务

java - 如何检查字符串中的逻辑运算符或将字符串转换为Java中的代码

android - 当我设置 listView.onScrollListener(this) 时调用 onScroll,但没有任何触摸

android - 获取多个图像的 Intent

android - 如何使用 Eclipse 生成我的 MD5 和 SHA1 指纹用于调试 keystore (Android)

android - 如何防止 Android 应用程序在使用 Xamarin Studio 部署期间被卸载?

android - 如何使用 Espresso 计数 RecyclerView 项目