答案 0 :(得分:3)
您忘记了break
陈述
switch(position) {
case 0:
Intent one = new Intent(MainActivity.this, BookDetails.class);
one.putExtra("jsonUrl", "url 1 here");
startActivity(one);
one.removeExtra("jsonUrl");
break; // here
case 1:
Intent two = new Intent(MainActivity.this, BookDetails.class);
two.putExtra("jsonUrl", "url 2 here");
startActivity(two);
two.removeExtra("jsonUrl");
break; // here
case 2:
Intent three = new Intent(MainActivity.this, BookDetails.class);
three.putExtra("jsonUrl", "url 3 here");
startActivity(three);
three.removeExtra("jsonUrl");
break; // here
在没有突破switch
的情况下,语句可以直接进入下一个条件。
答案 1 :(得分:1)
你没有在开关上使用中断。
switch(position) {
case 0:
Intent one = new Intent(MainActivity.this, BookDetails.class);
one.putExtra("jsonUrl", "url 1 here");
startActivity(one);
one.removeExtra("jsonUrl");
**break;**
case 1:
Intent two = new Intent(MainActivity.this, BookDetails.class);
two.putExtra("jsonUrl", "url 2 here");
startActivity(two);
two.removeExtra("jsonUrl");
**break;**
...