简体   繁体   English

如何在Android中的if循环中检查数组?

[英]How can i check array in if loop in android?

I have problem with if loop in array.I am working in Ginger bread source code and modify email app but problem in if loop in array.Show my code. 我在array中的if循环有问题。我正在使用Ginger面包源代码并修改电子邮件应用程序,但是在array中的if循环中存在问题。显示我的代码。

String[] arrayUri;
    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
    setContentView(R.layout.message_compose);
    //getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.list_title);
    Bundle b=this.getIntent().getExtras();
    arrayUri=b.getStringArray("uriList");
    //data1=getIntent().getExtras().getString("hello");
    mController = Controller.getInstance(getApplication());
    mListener = new Listener();
    initViews();
    if(arrayUri != null) //Not Working
    {
      makeToast("Hello");
    }

I used this one 我用这个

    if(!arrayUri.equals("")) //Not Working
    {
      makeToast("Hello");
    }


    if(arrayUri.length >0) //Not Working
    {
      makeToast("Hello");
    }

    if(arrayUri.length != 0) //Not Working
    {
      makeToast("Hello");
    }

Over all condition are not working in email app. 在所有情况下,电子邮件应用程序均无法正常工作。 any other way to compare array in if. 在if中比较数组的任何其他方式。

I haven't tested this (I'm 80% certain it'll work) 我尚未对此进行测试(我可以确定它会正常工作80%)

But it should get you on the path to an answer. 但这应该可以帮助您找到答案。

if (arrayUri.getClass().isArray()) {
  // I'm an array
} else {
  // I'm not an array
}

Use 采用

if(arrayUri == null || arrayUri.length == 0){
   toast("ARRAY EMPTY OR NULL");
} else {
   toast("Hello");
}

Convert your array into arrayList. 将您的数组转换为arrayList。 It might help you. 它可能会帮助您。 You can try this. 你可以试试看

ArrayList<String> lst;

     for(int i = 0; i < arrayUri.length; i++ )
     {
         lst.add(arrayUri[i]);
     }

if(lst.isEmpty())
     {

     }

Hope this will help you... 希望这个能对您有所帮助...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM