验证字符串并根据结果调用活动

时间:2012-12-10 11:46:42

标签: android

如果我的String值(from)为空,我想调用另一个活动,反之亦然:

    String[] from = new String[] { "name" };

    if (from.length >= 1)

    {
        int[] to = new int[] { R.id.countryTextView111};
        conAdapter = new SimpleCursorAdapter(CountryList.this, R.layout.countrylist, null, from, to);
        setListAdapter(conAdapter); // set adapter

    }   
    else 

    {

        Intent intent = new Intent(getApplicationContext(), EmailSettings.class);
        startActivity(intent);

    }

由于某些原因,我的条件无效,因此需要专家视图。

谢谢,

阿里

2 个答案:

答案 0 :(得分:1)

您正在检查数组长度,它包含一个条目,因此其长度 1
如果你想检查第一个条目的长度,那么

String[] from = new String[] { "name" };

if (from[0].length >= 1)

{
    int[] to = new int[] { R.id.countryTextView111};
    conAdapter = new SimpleCursorAdapter(CountryList.this, R.layout.emailsettings, null, from, to);
    setListAdapter(conAdapter); // set adapter

}   
else 

{

    Intent intent = new Intent(getApplicationContext(), EmailSettings.class);
    startActivity(intent);

}

答案 1 :(得分:0)

String[] from = new String[] { "name" };

for(int i=0;i<from.length;i++)
   {
      if(from[i]>="conditon")
       {
         //try code this
       }
   }