Why is this if statement skipped?
Can you tell me why the following if statement was skipped?
I want to check if my mAlphabetCode contains 0-9 literals instead of 0 to 9.
// check if alphabet code is numeric
if (mAlphabetCode.equals("0-9")){
mAlphabetCode = "-";
}
The complete code is as follows:
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (parent.getId() == R.id.lv_gl_content) {
store data to be pass
Intent mIntent = new Intent(this, AchList.class);
mIntent.putExtra("mPageUrl", mGameList.get(position).getItemPageUrl());
mIntent.putExtra("mGameTitle", mGameList.get(position).getTitle());
start activity and page animation
startActivity(mIntent);
mPageTrans.slideIn();
} else if (parent.getId() == R.id.lv_alphabet_content) {
get alphabet code
String mAlphabetCode = parent.getAdapter().getItem(position).toString().toLowerCase();
check if alphabet code is numeric
if (mAlphabetCode.equals("0-9")){
mAlphabetCode = "-";
}
build page url
mGameListUrl = mGameListUrl.substring(0, (mGameListUrl.length() - 2) ) + mAlphabetCode + "/";
mAlphabetMenu.setItemChecked(position, true);
close browsing menu
mSlidingPane.closePane();
make network request
mStringRequest = new StringRequest(Request.Method.GET, mGameListUrl, onSuccess(), onError());
mRequestQueue.add(mStringRequest);
}
}
This is what the debugger says mAlphabetCode contains before hitting the if statement:
My error is in my strings.xml file:
<!-- strings of arrays -->
<string-array name="slide_menu_alphabet">
<item>0– 9</item>
I have changed the project from 0-9 to 0 – ; 9 (the pitch shows the numbers so much) as the theme of the AndroidStudio IDE, thanks to @user1873880 and David Cesarino, I changed to 0 – ; 9 (the pitch is so numerically displayed), it works well now.
Thanks for your help.
Solution
The problem is that the “-” character in the code is actually the integer 45, while in the debugger it is 8211, which means it is a different character. You can verify this with some logs, just try to see this value (int) '-'
.