2013-03-28 52 views
0

/* txtOrigin 和txtDestination的值进行比较,以查询 变量假设它匹配/我想比较从我的表单到查询数据的用户输入。但我希望它不要区分大小写。我怎么做?

   if((origin.getText().toString().matches(queryOrigin)) 
         && (destination.getText().toString().matches(queryDestination))) 
       { 
       //proceed to route found layout 
        Intent openRouteFound = new Intent("com.icommute.feu.RouteFound"); 
        startActivity(openRouteFound); 
       } 

      /**compares the values of txtOrigin 
      and txtDestination to the query 
      variables assuming it doesn't match*/ 
       else 
       { 
       //proceed to no routes found layout 
        Intent openNoRoute = new Intent("com.icommute.feu.NoRoute"); 
        startActivity(openNoRoute); 
       } 

回答

5

请尝试:

if((origin.getText().toString().equalsIgnoreCase(queryOrigin)) 
     && (destination.getText().toString().equalsIgnoreCase(queryDestination))) 
{ 
    ... 
} 
+0

这解决了它。谢谢 – user2218813 2013-03-28 08:44:55

0

试试这个

origin.getText().toString().matches("(?i)" + queryOrigin)

这将使正则表达式CASE_INSENSITIVE

1

使用.equalsIgnoreCase()方法 如:

if((origin.getText().toString().equalsIgnoreCase(queryOrigin)) 
        && (destination.getText().toString().equalsIgnoreCase(queryDestination))) 
      { 

}

相关问题