私の質問の答えはおそらくそこにありますが、コンセプトを正しく理解しているかどうかはわかりません。if文のようなGson非同期の結果
私は成功しGsonでそれを読んで、それを私のトーストを表示することができる唯一の
{"meteo": "1"}
含む小さなJSONファイルを、しました。このようにそれに基づいて「if文」を行う場合
しかし
:私はトーストを行っているにもかかわらず、それは常にif文の第二部に行くif(meteoStatus == "1"){ // I know for sure it's 1
// Do something
} else {
// Do something else
}
をちょうどその前に、私の1を表示しますここで
は、コードの完全なセクションである:すべてのヘルプは高く評価されますStrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
String url = "http://www.boisdelacambre.be/ios/json/weather.php?key=53666d6c7b206a532d52403e414d2579";
String result = getUrlContents(url);
gsonInstance = new Gson();
meteo = new Meteo();
meteo = gsonInstance.fromJson(result, meteo.getClass());
String meteoStatus = meteo.getMeteo();
View rootView = inflater.inflate(R.layout.fragment_meteo, container, false);
ImageWeather = (ImageView) rootView.findViewById(R.id.imageWeather);
DonnesOuRemis = (TextView) rootView.findViewById(R.id.donnesOuRemis);
Toast.makeText(getActivity(), meteoStatus, Toast.LENGTH_LONG).show();
if(meteoStatus == "1"){
// il fait beau
Toast.makeText(getActivity(), "Pas remis !!", Toast.LENGTH_LONG).show();
ImageWeather.setImageResource(R.drawable.soleil);
DonnesOuRemis.setText("Donnés");
DonnesOuRemis.setTextColor(Color.parseColor("#06f828"));
} else {
Toast.makeText(getActivity(), "Pourquoi remis ??", Toast.LENGTH_LONG).show();
ImageWeather.setImageResource(R.drawable.pluie);
DonnesOuRemis.setText("Remis");
DonnesOuRemis.setTextColor(Color.parseColor("#f80b27"));
}
;-)
場合meteoStatus.equals( "1") ''してみてください –
作品!ありがとう(私が理由を理解していなくても)... –
[Javaで文字列を比較するにはどうすればよいですか?](http://stackoverflow.com/questions/513832/how-do-i-compare- strings-in-java) – Selvin