chr*_*olr 3 java android if-statement
无论如何可以告诉我为什么跳过以下if语句?我想检查我的mAlphabetCode是否包含0-9字面值,而不是0到9.
// check if alphabet code is numeric
if (mAlphabetCode.equals("0-9")){
mAlphabetCode = "-";
}
Run Code Online (Sandbox Code Playgroud)
这是整个代码:
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);
}
}
Run Code Online (Sandbox Code Playgroud)
以下是调试器在命中if语句之前说的mAlphabetCode包含的内容:

我的错误发生在我的strings.xml文件中:
<!-- strings of arrays -->
<string-array name="slide_menu_alphabet">
<item>0–9</item>
Run Code Online (Sandbox Code Playgroud)
我已经将项目从0-9更改为0– 9(间隔数字显示),因为AndroidStudio IDE受到了影响并感谢@ user1873880和David Cesarino,我更改为0- 9(间隔所以数字显示)现在它很棒.
谢谢您的帮助.
问题是你的代码中的' - '字符实际上是整数45,而在调试器中它是8211,这意味着它是不同的字符.您可以通过某些日志验证这一点,只是尝试查看此值(int) '-'.
| 归档时间: |
|
| 查看次数: |
279 次 |
| 最近记录: |