1
我有一個if語句不起作用,即使它是正確的,它也不檢查它的條件,我無法理解這種行爲。 請幫我找到錯誤。 這是我的代碼:如果陳述無法檢查條件
public Dialog onCreateDialog(int id) {
AlertDialog.Builder alert = new AlertDialog.Builder(this);
final SharedPreferences userPreferences = this.getSharedPreferences("strings", MODE_PRIVATE);
final Editor edit = userPreferences.edit();
switch (id) {
case 1:
alert.setTitle(lang_menu[3]);//"Gestione Preferiti"
alert.setIcon(R.drawable.ic_menu_star);
final String namesFav = userPreferences.getString("Name_Fav", "");
final String locfav = userPreferences.getString("Loc_Fav", "");
final String numfav = userPreferences.getString("Num_Fav", "");
final String subnumfav = userPreferences.getString("SubNumFav", "");
final String[] namesFavs = namesFav.split(";");
final String[] locfavs= locfav.split(";");
final String[] numfavs= numfav.split(";");
final String[] subnumfavs = subnumfav.split(";");
alert.setSingleChoiceItems(namesFavs, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
pos = item;
}
});
alert.setPositiveButton(lang_btn[2], new DialogInterface.OnClickListener() //"Visualizza"
{
public void onClick(DialogInterface dialog, int whichButton)
{
//if (SharedCode.isOnline(content)){
if (pos == -1){
Toast.makeText(content.getApplicationContext(), lang_error[2], Toast.LENGTH_LONG).show();//"Nessun preferito selezionato"
}else{
if (namesFavs[pos] == ""){
Toast.makeText(content.getApplicationContext(), lang_error[3], Toast.LENGTH_SHORT).show();//"Pagina inesistente"
}else{
prova= locfavs[pos];
SharedCode.loc = locfavs[pos].;
SharedCode.num = Short.parseShort(numfavs[pos]);
SharedCode.sub_num= Byte.parseByte(subnumfavs[pos]);
//-----------------------------------------------------------------------------------
if (SharedCode.loc == "aertel"){//this is the if that doesn't work
IrelandTeletext.getPage(content);
}
///////////////////////---------------------------------------------------------------
}
}
pos = -1;
}
});
break;
}
AlertDialog MyAlert = alert.create();
return MyAlert;
}
thk解釋的人,我想知道爲什麼==沒有工作 – user1001635
2-3個月前我遇到了同樣的問題。由於我來自C#背景,這種習慣已經習以爲常了 –