我需要有关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提前.. !!