我是android开发的新手,开始学习一些东西...我想知道如何实现我所知道的非常基础的一件事,但是我找不到用我对Android编程的实际知识来做到这一点的方法。已经尝试了几个小时,毕竟没有结果!我在堆栈上发现了很多问题,很多人问同样的事情,我已经尝试了很多,但毕竟没有成功!
我编写了以下代码,使用2种方法(vo2maxCalculo和shareIt),“ share it”方法应从MSG1变量获取值并将此值插入“ shareBody”字符串中,以便用户可以通过电子邮件共享它,等等。 ..
我怎样才能做到这一点?
非常感谢你!
public void vo2maxCalculo(View v) {
float minutos2;
double calculo2;
EditText minutos1 = (EditText) findViewById(R.id.minutos);
TextView resultado5 = (TextView) findViewById(R.id.vo2max12Resultado);
minutos2 = Float.parseFloat(minutos1.getText().toString());
calculo2 = 33 + 0.17 * (minutos2 - 1955) / 15;
String msg1 = String.format("%.2f", calculo2);
resultado5.setText(msg1);
}
public void shareIt(View v) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
String shareBody = String.format("The result is:", msg1);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Final Result");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
在这两个范围之外创建一个变量
String msg1; //Like this
public void vo2maxCalculo(View v) {
float minutos2;
double calculo2;
EditText minutos1 = (EditText) findViewById(R.id.minutos);
TextView resultado5 = (TextView) findViewById(R.id.vo2max12Resultado);
minutos2 = Float.parseFloat(minutos1.getText().toString());
calculo2 = 33 + 0.17 * (minutos2 - 1955) / 15;
msg1 = String.format("%.2f", calculo2); //Set it in here like this
resultado5.setText(msg1);
}
public void shareIt(View v) {
Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
sharingIntent.setType("text/plain");
//Can still use it in here as long as the other method got called first
String shareBody = String.format("The result is: %s", msg1);
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Final Result");
sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
startActivity(Intent.createChooser(sharingIntent, "Share via"));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句