Android:equalsIgnoreCase没有提供正确的输出

时间:2014-04-17 18:57:49

标签: java android

我需要有关Android代码的帮助。我正在使用CITIES(一个String数组)来与输入文本进行比较。

public void onClick(View v) {
        // TODO Auto-generated method stub
        Intent forwardIntent = new Intent(SourceActivity.this, DestinationActivity.class);
        AutoCompleteTextView inputSource = (AutoCompleteTextView) findViewById(R.id.source_city);

        String source_city = inputSource.getText().toString();
        if(source_city.equalsIgnoreCase(null))
        {
            Toast.makeText(SourceActivity.this, "Enter the name of city ", Toast.LENGTH_SHORT).show();
        }
        else
        {
            for(String city: CITIES){
                if(city.equalsIgnoreCase(source_city)){
                    forwardIntent.putExtra("source_city", source_city);
                    SourceActivity.this.startActivity(forwardIntent);
                    finish();
                    break;
                }
                else
                {
                    Toast.makeText(SourceActivity.this, "We don't have service for above mentioned city" + source_city, Toast.LENGTH_SHORT).show();
                    break;
                }

            }}
    }

问题在于,无论如何我都得到输出,因为我们没有为上述cityCITY名称提供服务;最后一个部分的Toast消息。任何人都可以帮助纠正这个问题。 Thnx提前.. !!

0 个答案:

没有答案