Created
August 28, 2015 13:01
-
-
Save survivingwithandroid/b2ce3eb565c234f3db22 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private Dialog createDialog() { | |
AlertDialog.Builder builder = new AlertDialog.Builder(this); | |
LayoutInflater inflater = this.getLayoutInflater(); | |
View v = inflater.inflate(R.layout.select_city_dialog, null); | |
builder.setView(v); | |
EditText et = (EditText) v.findViewById(R.id.ptnEdit); | |
.... | |
et.addTextChangedListener(new TextWatcher() { | |
.... | |
@Override | |
public void onTextChanged(CharSequence s, int start, int before, int count) { | |
if (count > 3) { | |
// We start searching | |
weatherclient.searchCity(s.toString(), new WeatherClient.CityEventListener() { | |
@Override | |
public void onCityListRetrieved(List<City> cities) { | |
CityAdapter ca = new CityAdapter(WeatherActivity.this, cities); | |
cityListView.setAdapter(ca); | |
} | |
}); | |
} | |
} | |
}); | |
builder.setPositiveButton("Accept", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
dialog.dismiss(); | |
// We update toolbar | |
toolbar.setTitle(currentCity.getName() + "," + currentCity.getCountry()); | |
// Start getting weather | |
getWeather(); | |
} | |
}); | |
builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
dialog.dismiss(); | |
} | |
}); | |
return builder.create(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment