android compare arrays(android比较数组)
问题描述
由于我在 android 开发方面不是最好的,所以我尝试了一些对我和朋友的手机有用的东西,但我有一些来自市场的报告说它可能不适用于所有设备并且做错比较.反正.该项目很简单,它从 sql 中获取一个订单,然后在游戏中玩家尝试完成它.所以我有2个数组.我一开始就这样称呼:
As I am not the best in android development, I tried something that works for me and for friend's mobile, but i have some reports from market that it doesn't work for all devices maybe and do wrong compare. Anyway. the project is simple, it grabs an order from sql and in the game the player try to finish it. So I have 2 arrays. I call this at start:
final String[] combo = new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
final String[] order1 = new String[] {"0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
for(int i = 0; i < combo.length; i++) {
combo[i] = new String();
combo[i] = "0";
order1[i] = new String();
order1[i] = "0";
}
在游戏过程中,如果玩家点击一个按钮,它会改变combo的值,例如combo[7] = "1";
and during the game if the player clicks a button it changes the value of combo, for example, combo[7] = "1";
当他点击最后一个按钮时,我用这个检查了 2 个数组
When he click the final button I check that 2 arrays with this
String IsSame = compareOrder(combo, order1);
然后
if (IsSame.equals("TRUE")) {
// commands
}
else if (IsSame.equals("FALSE")) {
// commands
}
private String compareOrder(String[] a, String[] b){
String n1 = "TRUE";
for (int i = 0; i < 13; i++) {
if (a[i].equals(b[i])==false) {n1 = "FALSE";}
}
return n1;
}
对我来说看起来没问题,而且它在我的手机上也能正常工作,但可能代码不那么正常,它会在其他设备上导致错误的结果.所以,我需要帮助,如果你看到一些奇怪的东西并且在我的代码中不起作用,请告诉我.谢谢!
It looks ok for me, and it's working for my mobile, but maybe the code is not so normal and it cause wrong results in other devices. So, I need help, if you see something strange and not working in my code, tell me. Thank you!
推荐答案
不要写已经提供的东西.:-)
Don't write what is provided already. :-)
import java.util.Arrays;
TextView tv = (TextView) findViewById(R.id.text_view);
tv.setText(Arrays.equals(order1, combo)? "Equal" : "Unequal");
这篇关于android比较数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:android比较数组


基础教程推荐
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 使用堆栈算法进行括号/括号匹配 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 如何对 Java Hashmap 中的值求和 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- 存储 20 位数字的数据类型 2022-01-01