- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我将这段 Java 代码放在一个混合和匹配两个文件的文件中。原始现有代码+用于绘制随机数据的代码。 (感谢 Dan 和 keshav 帮助完成这项工作)。
图表显示在绘制随机数据的应用程序上。我想将随机数据更改为我的数据。我有外部加速度计值,在应用程序中进一步加倍,并希望将这些值用于图形。
现在 double 所在的代码,正在写入文件:
@Override
public void onDataRecieved(TiSensor<?> sensor, String text) {
if (sensor instanceof TiAccelerometerSensor) {
final TiAccelerometerSensor accSensor = (TiAccelerometerSensor) sensor;
float[] values = accSensor.getData();
renderer.setRotation(values);
viewText.setText(text);
/**
* The code here, when button clicked, adds the contents of the
* edittext to the same file as x, y, and z
*/
Button confirmButton = (Button) findViewById(R.id.baddNametoFile);
confirmButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
try {
EditText bodyText;
bodyText = (EditText) findViewById(R.id.ETName);
// bodyText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
// CAPS LOCK
String name = bodyText.getText().toString();
PrintWriter out = new PrintWriter(new BufferedWriter(
new FileWriter(
"/sdcard/YS Data/Accelerometer.html",
true)));
out.println("<hr><br><br><br><h2 style=padding-left:20px;>"
+ name + "'s Data below" + "</h2><br>");
out.flush();
// new arraylist
out.close();
} catch (IOException e) {
Log.e(TAG, "Could not write file " + e.getMessage());
e.printStackTrace();
}
}
});
/**
* Code Below is for splitting the string (text) into three strings
* (x,y,z) of just numbers and then printing them to a file
*/
double doubx;
double douby;
double doubz;
String accval = text;
try {
PrintWriter writer = new PrintWriter(new BufferedWriter(
new FileWriter("sdcard/YS Data/Accelerometer.html",
true)));
String[] tempArr = accval.split("\\s+");
String x1 = tempArr[0];
String y1 = tempArr[1];
String z1 = tempArr[2];
String[] valxsplit = x1.split("=");
String x = valxsplit[1];
String[] valysplit = y1.split("=");
String y = valysplit[1];
String[] valzsplit = z1.split("=");
String z = valzsplit[1];
doubx = Double.parseDouble(x);
douby = Double.parseDouble(y);
doubz = Double.parseDouble(z);
writer.println("<h3 style=padding-left:20px;>" + "x is "
+ doubx + "<br>" + "y is " + douby + "<br>"
+ "Force is " + doubz + "</h3><br>");
writer.close();
} catch (IOException e) {
/** notification possibly */
e.printStackTrace();
}
}
}
//Then lots of code to do other things... then this in graph code
private int generateRandomNum() {
Random randomGenerator = new Random();
int randomInt = randomGenerator.nextInt(10);
return randomInt;
}
protected class Update extends AsyncTask<Context, Integer, String> {
@Override
protected String doInBackground(Context... params) {
int i = 0;
while (true) {
try {
Thread.sleep(700);
x11 = x11 + 5;
y11 = generateRandomNum();
publishProgress(i);
i++;
} catch (Exception e) {
}
}
// return "COMPLETE!";
}
// -- gets called just before thread begins
@Override
protected void onPreExecute() {
super.onPreExecute();
}// then more code... unrelated
我要改y11
, 从上面的代码到 doubx
,来自顶部的代码。当我尝试更改 y11
时至 doub x
在上面的代码中,我收到一条错误消息 doubx cannot be resolved to a variable
.
我想知道是否可以使用 intents 将 double 以及它们具有的值沿代码传递到我想再次使用它的地方,但是我知道 intents 通常用于传递数据 Activity ,而不是内部。再一次,我是 Java 的新手,不知道是否有比我想象的更简单的方法来做到这一点。如果有人知道方法请帮忙。
提前致谢
编辑:我在顶部添加了定义它们的代码:
double doubx etc...
成功了!好吧,我对代码进行了一些更改,我也对其进行了编辑。感谢 Ivan 和 sush 的回答 :D
最佳答案
在 trycatch 之外定义所有变量,我的意思是将它们作为成员变量。增加范围。都是本地范围内的变量。
double doubx = Double.parseDouble(x);
double douby = Double.parseDouble(y);
double doubz = Double.parseDouble(z);
关于java - 同一 Activity 中的 Intent - Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20786105/
如果我想为收藏创建一个 Intent 。 如果用户问“他最喜欢什么”,它会显示一些建议芯片 因此它会调用与该芯片相关的任何后续 Intent 。 最喜欢的饮料 最喜欢的食物 最喜欢的电影等 我还想直接
我确信有一些显而易见的事情,但还没有找到解决这个简单问题的方法。错误是在用户猜出正确答案时尝试启动另一个 Activity 的主要 Activity : Error:(85, 23) Unresolv
public class MainActivity extends Activity { Button b; //FrameLayout fl; @Override p
我对 intentService 有点困惑。文档说,如果您向 intentService 发送多个任务( Intent ),那么它将在一个单独的线程上一个接一个地执行它们。我的问题是 - 是否可以同时
我正在尝试从其他应用程序获取 mime 类型 text/plain 的 Intent 并将该文本存储在字符串类型的变量中。它在 onCreate 方法中工作正常,但是当我使用 singleTask 作
我想知道,2个代码有什么区别? newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
如何设置我的 Activity 以响应任何类型的共享 Intent 。 我试过:- 但是这不起作用,我已经阅读了http://developer.android.co
鉴于子类具有不同的上下文以及在单击监听器后启动的不同 Activity ,父类(super class)中的代码 Intent Intent=new Intent(context,Activity.c
更新#1:更多信息添加到这篇文章的末尾 我是 Android 开发和测试的新手。 我有 3 个 Espresso 测试。第一个测试通过,但第二个不会运行,因为在第二个测试之前调用 setUp() 方法
我是 Espresso UI 测试的新手。 我在运行测试时遇到这个错误(ADT Eclipse IDE)。 该应用程序已经开发完成,并且在启动该应用程序时有很多请求正在进行。无法重写应用程序。但我需要
因此,尝试创建一个我认为是基本简历应用程序的应用程序。我有两个类(class),都有同样的问题。它说它“无法解析符号 Intent ” 谷歌部分做了,但没有任何意义.. 这是我的代码。 MainAct
我正在尝试将 user_id 值从一个 Intent 传递到另一个 Intent。我知道这是一个非常简单的过程,而且我已经这样做了好几次了。但对于下面的代码,我有点困惑。 我需要将 user_id 值
这是我将值传递给名为 choice 的类的主要 Activity 。 @Override public void onClick(View v) { // TODO Auto-generated me
我正在寻找一个 Android Intent 来翻译文本,我发现了这个: Google Translate Activity not working anymore 但我想在任务管理器中使用它。我真的
可以设置多个启动 Intent ,例如,当用户点击通知时。 让我解释一下我的具体问题: 我有一个带通知的应用程序。每个通知都会打开一个不同的 Activity (也有不同的附加功能)。 现在我想提取有
我有一个 Intent launchIntent = packageManagerForListener.getLaunchIntentForPackage(packagesForAdapter[po
List targetedShareIntents = new ArrayList(); Intent shareIntent = new Intent(android.content.Intent.
所以我试图在选择列表中的项目后启动一个新 Activity ......根据我所读的内容非常基本。我也在尝试在附加功能中发送一个值。所以我可以选择列表中的项目,然后新 Activity 开始,extr
有没有一种方法可以将一个Intent bundle 从一个 Intent 传递到另一个 Intent ,而不必提取包并单独处理每个额外的 Intent ? 例子: intent2.setExtras(
这个问题在这里已经有了答案: Android 5.0 (L) Service Intent must be explicit in Google analytics (11 个答案) 关闭 6 个月
我是一名优秀的程序员,十分优秀!