Android的比较数组 [英] android compare arrays

查看:124
本文介绍了Android的比较数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,因为我不是在android开发最好的,我试过的东西,对于我和朋友的手机的工作原理,但我有一些报道,从市场,它不工作的所有设备,并可能错做比较。反正这个项目很简单,从SQL抢订单,并在游戏中玩家尝试完成它。所以,我有2个阵列。我把这种在启动:

Hi guys 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 that from market that it dont work for all devices maybe and do wrong compare. Anyway the project is simple, it grab 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";
    }

和游戏中,如果玩家点击组合的一个按钮,它的变化值,例如组合[7] =1;

and during game if the player click a button it change 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;  
}

这看起来不错对我来说,它的工作为我的手机,但也许是code是不那么正常的,这导致其他设备错误的结果。所以,我需要帮助,如果你看到一些奇怪的事情,在我的code不能正常工作,请告诉我。谢谢!

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的比较数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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